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

HELP! Touched Function not Working Properly?

Asked by 7 years ago

when i press the play button. it automatically turns the parts green without needing to touch the base part.

script.Parent.BasePart.Touched:connect(function() for i,v in pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green") end end)

4 answers

Log in to vote
0
Answered by
TNTeon -1
7 years ago

local function onTouch(hit)

pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green") end 

end

script.Parent.BasePart.Touched:connect(onTouch)

game.Workspace.mapStorage.map.King.Torso.Touched:connect(onTouch)

--I think this should work

Ad
Log in to vote
0
Answered by 7 years ago

the reason it is doing that is because if any part touches it then it will change so I recommend doing this

function Touch(hit)
    if hit.Parent == hit.Parent:FindFirstChild("Humanoid") then
    if (human~= nil) then -- checks if it's a player
for i,v in pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green")
             end 
        end
    end
end

script.Parent.Touched:connect(Touch)
0
Thanks. MaxOutGaming -3 — 7y
0
it worked? GameBoyOtaku 63 — 7y
Log in to vote
0
Answered by 7 years ago

Local B = script.Parent.BasePart

Local function boom() script.Parent.BrickColor = ("whatevercoloryouwant")

end

B.Touched:connect(boom)

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
7 years ago
Edited 7 years ago

Check this out!

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --check if it's an humanoid
        for i,v in pairs(script.Parent:GetChildren()) do
            v.BrickColor = BrickColor.new("Bright green")
        end
    end 
end)

If it works, please mark this answer as the correct one!

And as always, good scripting!

Answer this question