Hello everybody, i am using remote events to pass a screengui through to the server, but it comes as the player object instead. I have used typeof and chcked its name, and it’s exactly identical to the player object. I would like to know why this is happening if anybody could explain it to me. Thank you.
Can you provide the script in question?
There isn’t much to show, but i’ll show the lines in question in code format.
LocalScript:
RemoteEvent:FireServer(Player,CCS)
(CCS is screengui object, script calling FireServer is child of CCS)
Server Script:
RemoteEvent.OnServerEvent:Connect(function(Player,CCS)
print(typeof(CCS)) -- Instance
print(typeof(Player)) -- Instance
print(CCS.Name) -- dizzyscobby
print(Player) -- dizzyscobby
end)
Doesn’t tell much, can you show what Player
and CCS
refers to? RemoteEvent:FireServer(Player,CCS)
Well, player is…the player, and i stated CCS was a ScreenGui object above.
Don’t pass the player in when firing the remoteevent. It’s automatically the first argument.
Reference: RemoteEvent | Roblox Creator Documentation
The first parameter given for OnServerEvent is automatically set to player so you don’t have to send it manually
example:
localscript
remote:FireServer('hello')
script
remote.OnServerEvent:Connect(function(player, msg)
print(player.ClassName) -- 'Player'
print(msg) -- 'hello'
end
After doing this, the screengui object reads as nil. I was told in another one of my posts you had to pass the player through the remoteevent to properly handle anything else sent as an argument, so is there any workaround for this?
That is not true. What @legs_v said is correct. If the server is receiving a nil object, odds are the object being passed only exists on the client and not the server.
first parameter of OnServerEvent is already the player
so put this code in:
localscript:
RemoteEvent:FireServer(CCS)
serverscript:
RemoteEvent.OnServerEvent:Connect(function(player,CCS)
print(typeof(CCS)) -- print the type
print(typeof(player)) -- print the player
print(CCS.Name) -- print the player
print(player) -- print an instance
end)
hope this works!
Sorry to everybody for the fuss, what @MuPower said made me realize that i was cloning and passing that ScreenGui object on using LocalScripts, hence the server not being able to recognize it. Thank you to everybody for their solutions.