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
1 | function Clicked() |
2 | print ( "Clicked!" ) |
3 | local Edit = script.Parent.Parent |
4 | game.Lighting.GamePlay:FireServer(Edit) |
5 | end |
6 |
7 | script.Parent.MouseButton 1 Click:connect(Clicked) |
Here is the script on the servers end
01 | XP = game.ServerStorage.XPBar |
02 |
03 | function 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 |
09 | end |
10 |
11 | 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.
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.
1 | function Clicked() -- LOCAL |
2 | print ( "Clicked!" ) |
3 | local Edit = script.Parent.Parent |
4 | game.Lighting.GamePlay:FireServer() |
5 | Edit.Visible = false -- yep |
6 | end |
7 |
8 | script.Parent.MouseButton 1 Click:connect(Clicked) |
01 | XP = game.ServerStorage.XPBar -- SERVER |
02 |
03 | function 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 | end |
09 |
10 | 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.
01 | Sent = false |
02 |
03 | function 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 |
11 | end |
12 |
13 | script.Parent.MouseButton 1 Click:connect(Clicked) |
1 | XP = game.ServerStorage.XPBar -- SERVER |
2 |
3 | function 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 |
8 | end |
Any questions? Comments? Skepticism? Comment down below or PM me!
Citations