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

RemoteEvents not passing Variables?

Asked by
lomo0987 250 Moderation Voter
9 years ago

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

1function Clicked()
2    print("Clicked!")
3    local Edit = script.Parent.Parent
4    game.Lighting.GamePlay:FireServer(Edit)
5end
6 
7script.Parent.MouseButton1Click:connect(Clicked)

Here is the script on the servers end

01XP = game.ServerStorage.XPBar
02 
03function Change(Player,Edit)
04    print(Player.Name.." Has Started to Play!")
05    Player.Play.Value = 1
06    local Give = XP:Clone()
07    Give.Parent = Player.PlayerGui
08    Edit.Visible = false
09end
10 
11game.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

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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.

1function Clicked() -- LOCAL
2    print("Clicked!")
3    local Edit = script.Parent.Parent
4    game.Lighting.GamePlay:FireServer()
5    Edit.Visible = false -- yep
6end
7 
8script.Parent.MouseButton1Click:connect(Clicked)
01XP = game.ServerStorage.XPBar -- SERVER
02 
03function Change(Player,Edit)
04    print(Player.Name.." Has Started to Play!")
05    Player.Play.Value = 1
06    local Give = XP:Clone()
07    Give.Parent = Player.PlayerGui
08end
09 
10game.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.

01Sent = false
02 
03function Clicked() -- LOCAL
04    if not Sent then
05        Sent = true
06        print("Clicked!")
07        local Edit = script.Parent.Parent
08        local WaitUntilReturned = game.Lighting.GamePlay:InvokeServer()
09        Edit.Visible = false
10    end
11end
12 
13script.Parent.MouseButton1Click:connect(Clicked)
1XP = game.ServerStorage.XPBar -- SERVER
2 
3function game.Lighting.GamePlay.OnServerInvoke(Player)
4    print(Player.Name.." Has Started to Play!")
5    Player.Play.Value = 1
6    local Give = XP:Clone()
7    Give.Parent = Player.PlayerGui
8end

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


Citations

Client-Server Model

RemoteFunction and RemoteEvent Tutorial

Ad

Answer this question