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

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

Asked by 8 years ago

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.

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 TurboFusion 1821 — 8y
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 ;/ DevKarolus1 70 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

"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)
0
Dude you are awesome :D Thanks for help. DevKarolus1 70 — 8y
Ad

Answer this question