Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remote event is receiving the client instead of string?

Asked by 3 years ago
Edited 3 years ago

I'm not sure what's happening, anyone know why?

This is the local script:

script.Parent.RemoteEvent:FireServer("TestString")

Server side script:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(String) print(tostring(String)) end)

Instead of returning the string it instead returns the client's player?

Output reads: "wwwaylon09"

The local script, server side script, and remote event are all parented to a tool. Possibly a replication error?

Edit: I moved the remote event to replicated storage and the server side script to the workspace yet it still receives the client instead of the string.

1 answer

Log in to vote
1
Answered by 3 years ago

For any client to server communication through remotes, the first tuple passed is ALWAYS the player that triggered the remote.

The solution is to make the first tuple received either a dummy variable - put an underscore in its place - or initialise it as player:

-- local script
remoteEvent:FireServer(string)

-- server script
remoteEvent.OnServerEvent:Connect(function(_, string) -- you could very well replace '_' with 'player'
    print(string)
end)
0
I didn't realize there were 2 tuples involved with the connected function, thank you! wwwaylon09 113 — 3y
Ad

Answer this question