I have a brick that becomes visible on humanoid touch, but I want the color of the brick to be random on humanoid touch as well. Any help?
1 | function Hybric(hit) |
2 | local g = hit.Parent:findFirstChild( "Humanoid" ) |
3 | if (g ~ = nil ) then |
4 | Workspace.Part.Color = Color 3. new(math.random(), math.random(), math.random()) |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(Hybric) |
Well what you are saying when a Humanoid touches it well I dont know how to make it only when a Humanoid touches it but I can do when anything touches it.
1 | function onTouched (hit) |
2 | script.Parent.BrickColor = BrickColor.Random() |
3 | wait( 5.0 ) |
4 | end |
5 |
6 | script.Parent.touched:connect(onTouched) |
Here,This random() method is used to set a random value out of the available not including nil and to do that we use the event function that activates it.
1 | function Touched(hit) |
2 | if hit.Parent:findFirstChild( "Humanoid" ) then |
3 | Workspace.Part.BrickColor:random() |
4 | end |
5 | end |
6 | script.Part.Touched:connect(Touched) |