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

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

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)

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

GUI Script(Parent=PlayButton, LocalScript)

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

1 answer

✓ Accepted answer

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:

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

Server script:

game.ReplicatedStorage.PlayerSpawn.OnServerEvent:Connect(function(plr, t) --you can use the t variable in this function now
    plr.TeamColor = BrickColor.new("Bright red")
    plr:LoadCharacter()
end)

1 comment

0

alright! sorry for the 7-day delay but It worked

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