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

How would I change a brick color for one person?

Asked by 6 years ago

So I'm helping a friend and I'm not entirely sure how to change a brick color for just one person. Here is his code:

function onTouched(abc,hit) 

    if hit.Parent:FindFirstChildOfClass("Humanoid") then 

        wait(1)
        abc.BrickColor = BrickColor.Green()

    end 

end 

for i,v in pairs(script.Parent:GetChildren()) do 

    if v.Name == "check" then 

        v.Touched:Connect(function(hit) 

             onTouched(v,hit) 

        end) 

    end 

end

If you could point us in the right direction or help us out that would be awesome :)

1 answer

Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
6 years ago

So OnTouched only uses one parameter.And that parameter is the thing that touched it.

So here if your hand touched the brick the hit will be the hand and it parent of hit will the the player character model.

Note code is tested in studio and works.

function onTouched(hit) 

    if hit.Parent:FindFirstChildOfClass("Humanoid") then 
        wait(1)
        hit.BrickColor = BrickColor.Green()

    end 

end 

for i,v in pairs(script.Parent:GetChildren()) do 

    if v.Name == "check" then 

        v.Touched:Connect(function(hit) 

             onTouched(hit) 

        end) 

    end 

end
Ad

Answer this question