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

Can someone help me with ontouch change color to team outpost?

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.

2 comments

0

Explain what's happening and what errors you are getting. All you said was you want the script to do something but you didn't explain anything else

0

Becouse now it make when player touch it color will change, but i want to change color when player capture outpost... i know it's probably request, but i don't know how to fix it ;/

1 answer

✓ Accepted answer

"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)

1 comment

0

Dude you are awesome :D Thanks for help.

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