a ball that will change the color of the person when a person is hit and will explode after a time limit
I will go step by step on how to do this.
Start with this
script.Parent.Touched:connect(function(hit) end)
what I did is called an anonymous function and it is amazing so instead of you doing this.
function OnTouch(hit) end script.Parent.Touched:connect(hit)
after every single time you want to make that hit function(depending on what you are wanting of course...)
you can use the anonymous function and it will save you so much time.
Anyways this is the next step.
script.Parent.Touched:connect(function(hit) if hit.Parent then hit.BrickColor = BrickColor.random() end end)
that there checks to see if hit has a parent(everything has a parent so... gg) and then changes the part that was a hit to a random brickcolor.
now time for the explosion part :)
script.Parent.Touched:connect(function(hit) if hit.Parent then hit.BrickColor = BrickColor.random() -- space for cleanliness :) local explodeded = Instance.new("Explosion") end end)
this right here makes the variable "explodeded" the variable or whatever for the Explosion, it will create an explosion and is crucial to the script.
script.Parent.Touched:connect(function(hit) if hit.Parent then hit.BrickColor = BrickColor.random() -- space for cleanliness :) local explodeded = Instance.new("Explosion") wait(5) explodeded.Parent = script.Parent end end)
that will end the script, with after 5 seconds of being touched it explodes( it does not destroy it I will add that to so you know just incase.)
script.Parent.Touched:connect(function(hit) if hit.Parent then hit.BrickColor = BrickColor.random() -- space for cleanliness :) local explodeded = Instance.new("Explosion") wait(5) explodeded.Parent = script.Parent wait(1.5) script.Parent:Destroy() end end)
the above is incase you want it to destroy the ball, if not just ignore this portion and go with the one before this.
I hope I helped!
Like this,
script.Parent.Touched:connect(function(part) part.BrickColor = BrickColor.new("Really red") wait(10) local Boom = Instance.new("Explosion") Boom.Parent = game.Workspace Boom.Position = part end)
make a sphere and put a script inside the ball and copy this into the script.
Closed as Not Constructive by darkelementallord, rexbit, and M39a9am3R
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?