Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a bomb that after exploding, goes to a random position?

Hello! So I just made a bomb that turns red after 3 seconds and then explodes after 3 seconds. I was wondering if there was a way to change it's Vector3 position after it explodes... but I do not know how to change the Vector3 to a random location.

Here is my code for the bomb.

local terrain = game.Workspace.Terrain
local bomb = game.Workspace.bomb
local bomby = Instance.new("Explosion")

bomb.BrickColor = BrickColor.White()

bomb.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")
		then wait(3) bomb.BrickColor = BrickColor.Red()
	wait(3)
	bomby = Instance.new("Explosion")
	bomby.Position = bomb.Position
	bomby.Parent = game.Workspace
	bomb.BrickColor = BrickColor.White()
	end
end)

Also, if my coding is bad it's because I just started coding 3 days ago. Lol TYVM for your time and effort for helping me! It makes me so inspired and happy!

1 answer

✓ Accepted answer
math.randomseed(tick())
xparam=math.random(?,?)
zparam=math.random(?,?)
yparam=math.random(?,?)
bomb.Positon = Vector3.new(xparam,yparam,zparam)

This bit of code randomizes the position of the bomb.

Math.randomseed makes the seed for what the random numbers are, sorta like a minecraft seed. We just use "tick()" for the seed because it makes the numbers more random.

the variables are just the x, y, and z coordinates. replace the ?'s with the two numbers you want to be the lowest possible and highest possible, i.e math.random(1,100). 1 is lowest possible, 100 is highest possible.

I hope this helped!

BTW im new to scripting to LOL.

3 comments

0

In game math.randomseed(tick()) and os.time() don't make much of a difference .

0

loll. Your new, but your super good at it already, to me atleast. TYVM

0

Your welcome!

This discussion is preserved as it was. New answers, comments, and votes are closed.