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

GUI works in studio but not a published game, how would I fix this? It is a team change GUI.

Asked by 6 years ago

I'm using local scripts. It is a team change GUI. All works in studio, but not in a game. In-game it switches me to the selected team, but does not respawn me, or teleport me to the spawn position. The GUI does not disappear after I selected my team. As said before it works flawlessly on studio.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
player.TeamColor = BrickColor.new("Really black")
player:LoadCharacter()
script.Parent.Parent.Parent.Enabled = false
end)

Any help would be appreciated, thanks!

0
You should be handling anything that you want to replicate to all the players (anything you want them all to see) in a server script, not local. mattscy 3725 — 6y
0
I have tried doing this with server scripts, but then it completely did not work in the published game. DanielCXI -5 — 6y
0
i edited my answer DeceptiveCaster 3761 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
-- This is a server script, not a local script
script.Parent.MouseButton1Click:Connect(function()
    for _,p in pairs(game.Players:GetPlayers()) do
        if p.Name == "DanielCXI" then
            p.TeamColor = BrickColor.new("Really black")
            p:LoadCharacter()
            p.PlayerGui.ScreenGui.Enabled = true
        end
    end
end)

There were a couple things wrong with your script:

  • You are using connect(), which is now officially deprecated. Use Connect(). Seriously.

  • Changing only the LocalPlayer's properties didn't work (obviously), so you had to run a for loop for each player in-game.

0
Why not Players:FindFirstChild("DanielCXI") tho Amiaa16 3227 — 6y
0
Or even script.Parent:FindFirstAncestorOfClass("Player") since the gui is parented to someone's PlayerGui Amiaa16 3227 — 6y
Ad

Answer this question