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

Cannot send variable from Client to Server using RemoteEvents?

Asked by 5 years ago

I am making a Client to Server system and I want it to pass the name of the Script (the script has the same name as the player who created the "lobby", i.e. "Warriorfoox") and when I try to run the script it prints ServerScriptService.Scrpt:21: attempt to concatenate local 'GameName' (a userdata value)

Here's the client's local script:

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2local AttemptJoin = ReplicatedStorage.Folder:WaitForChild("AttemptJoin")
3local Player = game:GetService("Players").LocalPlayer
4 
5script.Parent.MouseButton1Click:Connect(function()
6    local NewName = script.Name
7    if script.Parent.Parent.Parent:FindFirstChild(NewName).players:FindFirstChild(Player.Name) then return end
8    AttemptJoin:FireServer(Player,NewName)
9end)

and here are all of the things that lead to the issue in the server's script (broken down):

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local Events = Instance.new("Folder", ReplicatedStorage)
03local AttemptJoin = Instance.new("RemoteEvent", Events)
04local JoinSuccess = Instance.new("RemoteEvent", Events)
05AttemptJoin.Name = "AttemptJoin"
06JoinSuccess.Name = "JoinSuccess"
07 
08function onAttemptJoin(Player,NewName)
09    print(Player.Name.." is trying to join "..NewName.."'s Game!")
10    if Player.PlayerGui.ScreenGui:FindFirstChild(NewName).players:FindFirstChild(Player.Name) then return end
11    JoinSuccess:FireAllClients(Player,NewName)
12end
13 
14AttemptJoin.OnServerEvent:Connect(onAttemptJoin)

(there is no issue with JoinSuccess so that code is not needed) If someone can tell me what is wrong and/or how to solve it, that would be massively appreciated.

Answer this question