Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

RemoteEvents not passing Variables?

I've been trying to make scripts that revolve around RemoteEvents, Everything is set up and should work but it doesn't seem to want to fully work. It seems like it can't get the variables i'm sending to the other script.

Here is the script on the players end

function Clicked()
	print("Clicked!")
	local Edit = script.Parent.Parent
	game.Lighting.GamePlay:FireServer(Edit)
end

script.Parent.MouseButton1Click:connect(Clicked)

Here is the script on the servers end

XP = game.ServerStorage.XPBar

function Change(Player,Edit)
	print(Player.Name.." Has Started to Play!")
	Player.Play.Value = 1
	local Give = XP:Clone()
	Give.Parent = Player.PlayerGui
	Edit.Visible = false
end

game.Lighting.GamePlay.OnServerEvent:connect(Change)

EVERYTHING works until line 8, "Edit.Visible = false". It can't get "Edit" as a variable. My other scripts are acting like this too, it works until it gets to the variables.

1 answer

✓ Accepted answer

I assume that the FilteringEnabled property is defined as true.

Here's the thing about sending objects from the client to the server: Don't do it. Client objects, such as GUIs or LocalScripts, are replicated to each client and, due to the Client-Server Model, can not be accessed by the server. What you can do is redefine the Visible property of Edit in the LocalScript you have there.

function Clicked() -- LOCAL
    print("Clicked!")
    local Edit = script.Parent.Parent
    game.Lighting.GamePlay:FireServer()
    Edit.Visible = false -- yep
end

script.Parent.MouseButton1Click:connect(Clicked)
XP = game.ServerStorage.XPBar -- SERVER

function Change(Player,Edit)
    print(Player.Name.." Has Started to Play!")
    Player.Play.Value = 1
    local Give = XP:Clone()
    Give.Parent = Player.PlayerGui
end

game.Lighting.GamePlay.OnServerEvent:connect(Change)

If you want to wait until the RemoteEvent is called to the server, then render Edit invisible, then use a RemoteFunction instead, as it waits until it is returned (synchronous). I recommend to implement debouncing in the client to avoid multiple fires to the server.

Sent = false

function Clicked() -- LOCAL
    if not Sent then
        Sent = true
        print("Clicked!")
        local Edit = script.Parent.Parent
        local WaitUntilReturned = game.Lighting.GamePlay:InvokeServer()
        Edit.Visible = false
    end
end

script.Parent.MouseButton1Click:connect(Clicked)
XP = game.ServerStorage.XPBar -- SERVER

function game.Lighting.GamePlay.OnServerInvoke(Player)
    print(Player.Name.." Has Started to Play!")
    Player.Play.Value = 1
    local Give = XP:Clone()
    Give.Parent = Player.PlayerGui
end

Any questions? Comments? Skepticism? Comment down below or PM me!


Citations

Client-Server Model

RemoteFunction and RemoteEvent Tutorial

This discussion is preserved as it was. New answers, comments, and votes are closed.