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

Why does my teamchange work in Studio but not in the actual game?

I made a team changer script so that when you choose a team, the gui would disable and change your team and respawn you. It works in studio, but not in the game itself. Here is the script:

local player = game.Players.LocalPlayer
local teamgui = game.StarterGui.TeamChanger

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

1 comment

0

The client's UI is not located in StarterGui

1 answer

✓ Accepted answer

Is FilteringEnabled on? If so, this code will work in Studio but not on an actual server.

To solve the problem, you'll need to use a RemoteEvent. Here's how I'd structure it:

First off, have a RemoteEvent in ReplicatedStorage. Let's say its name is TeamChanged.

In a script in ServerScriptStorage:

local event = game.ReplicatedStorage:WaitForChild("TeamChanged")

event.OnServerEvent:connect(function(player, color)
    player.TeamColor = color
end)

Replace the script you posted with this:

local event = game.ReplicatedStorage:WaitForChild("TeamChanged") -- This is new
local player = game.Players.LocalPlayer
local teamgui = game.StarterGui.TeamChanger

script.Parent.MouseButton1Click:connect(function()
    teamgui.Enabled = false
    event:FireServer(BrickColor.new("Really black")) -- This is new
    player:LoadCharacter()
end)

Hopefully this is simple enough; you can read more about RemoteEvents here if you're having trouble understanding.

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