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)
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)