Cannot send variable from Client to Server using RemoteEvents?
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:
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local AttemptJoin = ReplicatedStorage.Folder:WaitForChild( "AttemptJoin" ) |
3 | local Player = game:GetService( "Players" ).LocalPlayer |
5 | script.Parent.MouseButton 1 Click: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) |
and here are all of the things that lead to the issue in the server's script (broken down):
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local Events = Instance.new( "Folder" , ReplicatedStorage) |
03 | local AttemptJoin = Instance.new( "RemoteEvent" , Events) |
04 | local JoinSuccess = Instance.new( "RemoteEvent" , Events) |
05 | AttemptJoin.Name = "AttemptJoin" |
06 | JoinSuccess.Name = "JoinSuccess" |
08 | function 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) |
14 | AttemptJoin.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.