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

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

Asked by 7 years ago

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)
0
The client's UI is not located in StarterGui Goulstem 8144 — 7y

1 answer

Log in to vote
0
Answered by
Lumez 15
7 years ago

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.

Ad

Answer this question