eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Ok, so I don't want to edit anything. I just want to read items off of their. For some reason when I create a 1 player server in studio, nothing from the StarterGui shows up in the PlayerGui tab. But for some reason stuff from the StarterPack shows up from the backpack. Is there way to access the PlayerGui at all?
I tried Remote Events also but it still can't find anything in the PlayerGui.
Local:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local ItemName = script.Parent.Parent:WaitForChild("Item")
local Remote = character:WaitForChild("WeaponDrop")
local RemoteA = Remote:WaitForChild("DropEvent")
repeat wait() until ItemName.Value ~= "None" -- Waits until It's the value of a real Weapon
script.Parent.MouseButton1Click:connect(function()
RemoteA:FireServer()
print('Fired!')
end)
Regular (Only Showing Part because it's long and not needed):
local RemoteA = script:WaitForChild("DropEvent")
RemoteA.OnServerEvent:connect(function(player)
print('Received!')
-- Loading Assets --
local character = player.Character or player.CharacterAdded:wait()
local PlayerGui = player:WaitForChild("PlayerGui")
local Torso = character:FindFirstChild("Torso")
local StarterGear = player:WaitForChild("StarterGear")
local Backpack = player:WaitForChild("Backpack")
print('Waiting for Inventory.....') <-- Stops here after printing
local MainGui = PlayerGui:WaitForChild("MainInv")
print('Inventory Loaded!')
local ItemName = MainGui.Options:WaitForChild("Item")
|
|
|
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui:WaitForChild("ScreenGui") |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
I meant from a server script xD
|
|
|
This is one of the cases where the difference between RemoteEvents and RemoteFunctions is vital.
RemoteEvents are pieces of code that can be executed from client to server, vice versa. RemoteFunctions act in a similar way, but can return values back to the sender just like a normal function. This would be useful in your case.
With FE, the gui in the PlayerGui only exists on the client, and therefore can only be accessed from a LocalScript. Try using a RemoteFunction in a LocalScript that can return the gui to your script. Or use a RemoteEvent to make all the changes to the gui in a LocalScript. |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
How would I go about doing that? Like returning the gui to the regular script
|
|
|
Lookup RemoteFunctions on the wiki and how to use them. You can then create a LocalFunction that returns the gui from a local script. Then you could store it as a variable in your regular script:
local gui = game.Workspace.MyRemoteFunction:InvokeClient(player) |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
I know how to do the :Invoke stuff already and the OnInvoke things but I don't how I would return the gui still. But I am going to look up some tutorial about remotefunctions. thanks for the help
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Use RemoteEvents instead
And also, stop trying to read the playergui from the server. Read the values from the client then just send the info to the server. Like I said before just use 1. Only ONE remote event stored in replicated storage. You don't need to make multiple res.
--server script
local re = game.ReplicatedStorage:WaitForChild("DropEvent")
re.OnServerEvent:connect(function(plr,value)
print(value)
end)
--local script
local re = game.ReplicatedStorage:WaitForChild("DropEvent")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local PlayerGui = player:WaitForChild("PlayerGui")
local Torso = char:FindFirstChild("Torso")
local StarterGear = player:WaitForChild("StarterGear")
local Backpack = player:WaitForChild("Backpack")
local MainGui = PlayerGui:WaitForChild("MainInv")
local ItemName = MainGui.Options:WaitForChild("Item")
repeat wait() until ItemName.Value ~= "None"
script.Parent.MouseButton1Click:connect(function()
re:FireServer(ItemName.Value)
end) |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Thanks, I understand it now ;D
|
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Wait Should I use a RemoteFunction if I want to wait until the Server is done before continuing?
|
|
|
Yes. You can write the code so that you wait until you get the return value of the RemoteFunction you called. |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Ok I have a easy problem when CallingClient.
How Do I get the specific person to call it too.
Regular:
Remote.OnServerEvent:connect(function(player,value)
ClientRemote:FireClient(player) <-- Can I still use the 'player' that called me above?
|
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Nevermind, silly mistake.
The LocalScript that's suppose to receive the call was disabled. My bad xD
|
|