Hello everyone, I have problem, becouse i want to make when team will get outpost, parts should change colors on team color.
Here is script:
local ting = 0 function OnTouch (Part) if ting == 0 then ting = 1 local Humanoid = Part.Parent:FindFirstChild("Humanoid") if Humanoid then local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent) if Player then script.Parent.Parent.Parent.Lights.Ball.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.Ball2.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.Ball3.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C1.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C2.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C3.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C4.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C5.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C6.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C7.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C8.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C9.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C10.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C11.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.C12.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.L1.BrickColor = Player.TeamColor script.Parent.Parent.Parent.Lights.L2.BrickColor = Player.TeamColor end end end ting = 0 end script.Parent.Parent.CLight.Touched:connect(OnTouch)
ting is debounce.
"becouse i want to make when team will get outpost". What happens when the team gets the outpost? Is it that a Touched
event occurs? No, someone could touch the part before or after the team gets the outpost (or not at all). Instead, I believe you have a CurrentOwner
BrickColorValue that represents the current owner of the team (with one colour representing 'neutral'). You need to set up the event to listen to that.
Thus, you can remove all the "ting"/debounce and humanoid checking parts of the code. To get the player's TeamColor, you simply read the value of CurrentOwner
.
Another improvement: if you want to change the colour of all the immediate children in the "Lights" folder, we can use a simple loop for that.
Resulting script:
local currentOwner = ________________ (path to CurrentOwner BrickColorValue here) local lights = ____________(path to lights here) currentOwner.Changed:connect(function(value) --value will be the TeamColor local children = lights:GetChildren() for i = 1, #children do --Change the color of each child, if it's a BasePart if children[i]:IsA("BasePart") then children[i].BrickColor = value end end end)