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

How do i use Math Random?

I've looked on the Roblox wiki but found it confusing, i gave it ago anyway but it doesn't work so i assume I've done it wrong.

local Dobounce = true

while Dobounce == true do wait()
	if script.Parent.Health <= 50 then
		local PositionX = script.Parent.Parent.HumanoidRootPart.Position.X
		local PositionZ = script.Parent.Parent.HumanoidRootPart.Position.Z
		local PositionY = script.Parent.Parent.HumanoidRootPart.Position.Y
		local Blood = game.ServerStorage.Misc.Blood:Clone()
		Blood.Parent = script.Parent.Parent
		Blood.Position = Vector3.new(PositionX,PositionY -3,PositionZ)
		Blood.Orientation = Vector3.new(0,math.random,90)
		Dobounce = false
	end
end

Any help is much appreciated!

2 answers

✓ Accepted answer
local Dobounce = true

while Dobounce == true do wait()
    if script.Parent.Health <= 50 then
        local PositionX = script.Parent.Parent.HumanoidRootPart.Position.X
        local PositionZ = script.Parent.Parent.HumanoidRootPart.Position.Z
        local PositionY = script.Parent.Parent.HumanoidRootPart.Position.Y
        local Blood = game.ServerStorage.Misc.Blood:Clone()
        Blood.Parent = script.Parent.Parent
        Blood.Position = Vector3.new(PositionX,PositionY -3,PositionZ)
        Blood.Orientation = Vector3.new(0,math.random(0,360),90)
        Dobounce = false
    end
end

you need numbers in math.random() and it will pick a random number between those 2 numbers so here it will pick a random number between 0 and 360

1 comment

0

Yea i just figured it out, Thank you for the help :)

I figured it out as i posted it but i'll give how i did it anyway, I guess you have to add parameters in which it gives the number and as im doing rotation i want it to do from 0 to 360, Here it is fixed:

local Dobounce = true

while Dobounce == true do wait()
	if script.Parent.Health <= 50 then
		local PositionX = script.Parent.Parent.HumanoidRootPart.Position.X
		local PositionZ = script.Parent.Parent.HumanoidRootPart.Position.Z
		local PositionY = script.Parent.Parent.HumanoidRootPart.Position.Y
		local Blood = game.ServerStorage.Misc.Blood:Clone()
		Blood.Parent = script.Parent.Parent
		Blood.Position = Vector3.new(PositionX,PositionY -3,PositionZ)
		Blood.Orientation = Vector3.new(0,math.random(0,360),90)
		Dobounce = false
	end
end

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