Actual Random Numbers

How would i go about a random number every time?
im making a bowling system and using math.random to decide where the pins fly
The problem is it picks 1 random number i need a random number for x, y, z and for the other 10 pins

workspace.ActiveBalls.ChildAdded:Connect(function(ball)
	ball.Touched:Connect(function(toutcher)
		if toutcher.Name == "Pin1" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin2" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin3" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin4" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin5" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin6" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin7" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin8" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin9" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
		if toutcher.Name == "Pin10" then
			toutcher.CanCollide = false
			toutcher.CanTouch = false	
			toutcher.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
		end
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

why not just run math.random() 3 times?

2 Likes

alr tried that it does the same thing Ps thanks for all the help

1 Like
1 Like

Random.new() also could work

I dont entirely understand the problem, but I am curious why you do not just turn up the elasticity and elasticity weight on the pins so when the ball hits the pin it goes flying in the proper direction?

This way the pins would interact with eachother like real life. Imagine youre trying to hit a split. Sending the pins in random directions would not work to knock the other pin over.

I would also recommend that you use a for i,v in pairs loop instead and check the name of the hit part (v) then.

For example:

local pins = workspace:FindFirstChild("Pins") -- or wherever you have your pins stored

for i,v in pairs(pins:GetChildren()) do
	-- v == pin
	v.Touched:Connect(function(ball)
		if not ball == workspace.ActiveBalls then return end
		v.Velocity = Vector3.new(math.random(100,200), math.random(100,200), math.random(100,200))
	end)
end

If you are not familiar with for loops I suggest checking out this thread on loops, the roblox docs are also super useful for everything roblox scripting related

Sorry if I was not of much help on the random front