Hello everyone, It should change brick color on team color, but probably something is wrong.
Here is script:
local ting = 0 function OnTouch (CLight) if ting == 0 then ting = 1 script.Parent.Parent.Parent.Lights.Ball.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C1.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C2.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C3.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C4.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C5.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C6.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C7.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C8.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C9.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C10.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C11.BrickColor = game.Players.LocalPlayer.TeamColor script.Parent.Parent.Parent.Lights.C12.BrickColor = game.Players.LocalPlayer.TeamColor end ting = 0 end script.Parent.Parent.CLight.Touched:connect(OnTouch)
First off, I recommend you learn the 'for' statement, as it makes functions such as these much easier
Second, what does 'ting' do? I am assuming it is a debounce (Though it does not work correctly).
Thirdly, is this a 'Script' or 'LocalScript'? As LocalPlayer returns nil in 'Script' objects.
Test this code out to see if I have corrected your issue:
local DebounceTime = 0.5 local Debounce = false local Lights = script.Parent.Parent.Parent.Lights -- Touch events return the part that touched the object they were called from local OnTouch = function(Part) local Humanoid = Part.Parent:FindFirstChild("Humanoid") -- Checks to see whether the parent is a character if Humanoid then local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent) -- Tries to get the player that touched it if Player then if not Debounce then -- Makes sure a touched event hasn't already fired before the time you want it to Debounce = true local Color = Player.TeamColor Lights.Ball.BrickColor = Color for I = 1, 12 do -- Sets the color of each light to the player's team color local Light = Lights:FindFirstChild("C"..I) if Light then Light.BrickColor = Color end end wait(DebounceTime) Debounce = false -- Allows the event to fire again end end end end script.Parent.Parent.CLight.Touched:connect(OnTouch)