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

Local script, Filtering Enabled, Team Switch (GUI) problems?

This is in a local script. Filtering Enabled is active.

script.Parent.Parent.SwitchTeamsFrame.Rebels.MouseButton1Click:connect(function()
	gamer.TeamColor = BrickColor.new("Bright red")
	gamer:LoadCharacter()
end)

I press test in studio, and it works fine, go in game and it doesn't work.

2 answers

The whole point of Filtering Enabled is to disallow a LocalScript from making server changes. This includes anything from teams, brick colors, character modification (WalkSpeed, inserting a hat, etc) and others which I won't mention.

So, for this, we will need to use FireServer in a RemoteEvent for this. FireServer fires the OnServerEvent event on the server using the arguments specified with an additional player argument at the beginning.

As a result, we will be communicating from the Local side to the Server side. If you want a full tutorial on how this whole "Filtering Enabled" feature works, be sure to check out the wiki here

Anyway, here's the script on the local side

-- LocalScript
script.Parent.Parent:WaitForChild("SwitchTeamsFrame").Rebels.MouseButton1Click:connect(function()
    local teamColor = BrickColor.new("Bright red") --  change to whatever you want
    game:GetService("ReplicatedStorage"):WaitForChild("ChangeTeam"):FireServer(teamColor)
end)

Next, you need to insert this script into ServerScriptService and insert the following code

-- Localscript
local event = Instance.new("RemoteEvent",game.ReplicatedStorage) -- inserting the event
event.Name = "ChangeTeam" -- Naming the event

event.OnServerEvent:connect(function(gamer,teamColor) -- When the server is called (player, color of the team to change to)
    gamer.TeamColor = teamColor -- Changing the color
    gamer:LoadCharacter() -- Reloading the character
end)

If you have any questions or don't understand something, drop me a comment.

I solved all my life problems

Transform your LocalScript into a script, and insert it into the TextButton you're referring

script.Parent.MouseButton1Click:connect(function(player)
	repeat wait() until player.Character
	repeat wait() until player:WaitForChild("PlayerGui")
	player.TeamColor = BrickColor.new("Bright red")
	player:LoadCharacter()
end)

If this works, mark as the solution, please.

As always, good scripting!

1 comment

0

That didn't work...

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