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

This play button script only works In Studio and not In Server?

Asked by 6 years ago

I tested this script, and it worked, but when I test a server it doesn't work.. It's supposed to spawn the player in a specific team and load the character but it only works when I test in general in studio but in a server it doesn't work at all.. I tried to make the main script a local script but it doesn't work neither on server or on client. On server or studio there are no errors..

Main script(Parent=Workspace, ServerScript)

1game.ReplicatedStorage.PlayerSpawn.OnServerEvent:Connect(function(plr)
2    local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
3    local t = house.PlayButton.Text
4    plr.PlayerGui.GameChooseGUI.Frame.Visible = false
5    plr.TeamColor = BrickColor.new("Bright red")
6    plr:LoadCharacter()
7    house:Destroy()
8end)

GUI Script(Parent=PlayButton, LocalScript)

1local plr = game.Players.LocalPlayer
2local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
3local t = house.PlayButton.Text
4script.Parent.MouseButton1Click:Connect(function()
5    game.ReplicatedStorage.PlayerSpawn:FireServer()
6end)

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

If the gui is in StarterGui and the game is Filtering Enabled, then the server cannot see the gui, so you cannot index it from a server script.

You should rather pass the t variable from the client using the remote event, which idk what is for in the first place if you never even use it but whatever. Same for frame visibility.

Local script:

1local plr = game.Players.LocalPlayer
2local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
3local t = house.PlayButton.Text
4script.Parent.MouseButton1Click:Connect(function()
5    game.ReplicatedStorage.PlayerSpawn:FireServer(t) --pass the t variable
6    house.Visible = false --hide it on the client, not server
7end)

Server script:

1game.ReplicatedStorage.PlayerSpawn.OnServerEvent:Connect(function(plr, t) --you can use the t variable in this function now
2    plr.TeamColor = BrickColor.new("Bright red")
3    plr:LoadCharacter()
4end)
0
alright! sorry for the 7-day delay but It worked mudathir2007 157 — 6y
Ad

Answer this question