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:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AttemptJoin = ReplicatedStorage.Folder:WaitForChild("AttemptJoin")
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local NewName = script.Name
    if script.Parent.Parent.Parent:FindFirstChild(NewName).players:FindFirstChild(Player.Name) then return end
    AttemptJoin:FireServer(Player,NewName)
end)

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = Instance.new("Folder", ReplicatedStorage)
local AttemptJoin = Instance.new("RemoteEvent", Events)
local JoinSuccess = Instance.new("RemoteEvent", Events)
AttemptJoin.Name = "AttemptJoin"
JoinSuccess.Name = "JoinSuccess"

function onAttemptJoin(Player,NewName)
    print(Player.Name.." is trying to join "..NewName.."'s Game!")
    if Player.PlayerGui.ScreenGui:FindFirstChild(NewName).players:FindFirstChild(Player.Name) then return end
    JoinSuccess:FireAllClients(Player,NewName)
end

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.

Answer this question