Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i use Math Random?

Asked by
PastDays 108
5 years ago

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

Log in to vote
1
Answered by 5 years ago
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

0
Yea i just figured it out, Thank you for the help :) PastDays 108 — 5y
Ad
Log in to vote
0
Answered by
PastDays 108
5 years ago

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

Answer this question