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

Make a script do something either every 60 seconds or 120 seconds, no in-between?

Asked by 6 years ago
Edited 6 years ago

I'm not sure how to make a script do something every 60 seconds or every 120 second. I tried math.random but it isn't precise enough. I know this is kind of a "noob" question but for some reason I can't do it. (More specially I need the script to run for either 60 or 120 seconds & then stop for 180 seconds)

Here is the code I need to do this with:

Player = game.Players.LocalPlayer

Camera = game.Workspace.CurrentCamera

repeat wait() until Player.Character ~= nil

Torso = Player.Character:WaitForChild("Torso")

Rain = Instance.new("Sound", Camera)
Rain.SoundId = "http://www.roblox.com/asset/?ID=236148388"
Rain.Looped = true
Rain:Play()

function Particle(cframe)
    local Spread = Vector3.new(math.random(-100, 100), math.random(-100, 100), math.random(-100, 100))
    local Part = Instance.new("Part", Camera)
    local Smoke = Instance.new("Smoke", Part)
    Part.CanCollide = false
    Part.Transparency = 0.25
    Part.Reflectance = 0.15
    Smoke.RiseVelocity = -25
    Smoke.Opacity = 0.25
    Smoke.Size = 50
    Part.BrickColor = BrickColor.new("Steel blue")
    Part.FormFactor = Enum.FormFactor.Custom
    Part.Size = Vector3.new(0.15, 2, 0.15)
    Part.CFrame = CFrame.new(cframe.p + (cframe:vectorToWorldSpace(Vector3.new(0, 1, 0)).unit * 150) + Spread) * CFrame.Angles(0, math.atan2(cframe.p.X, cframe.p.Z) + math.pi, 0)
    game:GetService("Debris"):AddItem(Part, 3)
    Instance.new("BlockMesh", Part)
    Part.Touched:connect(function(Hit)
        Part:remove()
    end)
end

function Roof(cframe)
    return game.Workspace:FindPartOnRay(Ray.new(cframe.p, cframe.p * Vector3.new(0, 150, 0)), Player.Character)
end

while Camera ~= nil and Torso ~= nil do
    wait()
    if Roof(Torso.CFrame) == nil then
        for _ = 1, 5 do
            if (Camera.CoordinateFrame.p - Torso.CFrame.p).magnitude > 100 then
                Particle(Camera.CoordinateFrame)
                Particle(Torso.CFrame)
            else
                Particle(Torso.CFrame)
            end
        end
        Rain.Volume = 0.5
    else
        Rain.Volume = 0.1
        if Roof(Camera.CoordinateFrame) == nil then
            for _ = 1, 5 do
                Particle(Camera.CoordinateFrame)




            end
        end
    end
end

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

The solution, is to take the math.random output and assign each possible value to a number. For example:

local num = math.random(0, 1)
if num == 0 then
    wait(60)
else
    wait(120)
end
wait(180)
Ad

Answer this question