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

How can i put together that two scripts?

Asked by 5 years ago

I have that two scripts: And ,if its possible, i want to "pause" the second one when the first one detects both values ==1

First one


while true do if script.Parent.V.Value == 1 and Light.Value == 1 then script.Parent.Base.PointLight2.Range = 18 script.Parent.Humanoid.WalkSpeed = 30 end

Second one

while true do 
wait(1)
script.Parent.HumanoidRootPart.Steps:Stop()
script.Parent.Base.PointLight.Range = 0 
script.Parent.Base.PointLight2.Range = 0
script.Parent.Humanoid.WalkSpeed = 6 
script.Parent.V.Value = 1
local Player = game:GetService("Players").LocalPlayer
local stats = Player:WaitForChild("leaderstats")
local Light = Player.leaderstats.Light
if script.Parent.V.Value == 1 and Light.Value == 1 then
    script.Parent.Base.PointLight2.Range = 18
    script.Parent.Humanoid.WalkSpeed = 30
else

end 
wait(math.random(7 ,10)) 
script.Parent.V.Value = 0
script.Parent.Base.PointLight.Range = 18
script.Parent.Humanoid.WalkSpeed = 25
wait (1)
if Light.Value == 1 then
    script.Parent.Humanoid.WalkSpeed = 6 
    script.Parent.HumanoidRootPart.Anchored = true
    script.Parent.HumanoidRootPart.Scream:Play()
    script.Parent.HumanoidRootPart.Steps:Stop()
    wait (2)
    script.Parent.HumanoidRootPart.Steps:Stop()
    script.Parent.HumanoidRootPart.Scream:Stop()
    script.Parent.Base.PointLight.Range = 0 
    script.Parent.Base.PointLight2.Range = 0
    wait (3)
    script.Parent.HumanoidRootPart.Anchored = false
    script.Parent.Humanoid.WalkSpeed = 6 
    script.Parent.V.Value = 1
wait (3)
end

end 

1 answer

Log in to vote
1
Answered by
popeeyy 493 Moderation Voter
5 years ago
Edited 5 years ago

Yes, you are able to put them into one script using the spawn function. Here's more info on it. http://robloxdev.com/articles/Thread-Scheduler Here's how I would do it:

local pause = false

spawn(function()
    while true do
        if script.Parent.V.Value == 1 and Light.Value == 1 then
                script.Parent.Base.PointLight2.Range = 18
                script.Parent.Humanoid.WalkSpeed = 30
            pause = true --Pauses the loop
        else
            pause = false --Resumes the loop.
        end 
    end
end)

while true do 
    wait(1)
    if not pause then
    script.Parent.HumanoidRootPart.Steps:Stop()
    script.Parent.Base.PointLight.Range = 0 
    script.Parent.Base.PointLight2.Range = 0
    script.Parent.Humanoid.WalkSpeed = 6 
    script.Parent.V.Value = 1
    local Player = game:GetService("Players").LocalPlayer
    local stats = Player:WaitForChild("leaderstats")
    local Light = Player.leaderstats.Light
    if script.Parent.V.Value == 1 and Light.Value == 1 then
        script.Parent.Base.PointLight2.Range = 18
        script.Parent.Humanoid.WalkSpeed = 30
    end 
    wait(math.random(7 ,10)) 
    script.Parent.V.Value = 0
    script.Parent.Base.PointLight.Range = 18
    script.Parent.Humanoid.WalkSpeed = 25
    wait (1)
    if Light.Value == 1 then
            script.Parent.Humanoid.WalkSpeed = 6 
        script.Parent.HumanoidRootPart.Anchored = true
        script.Parent.HumanoidRootPart.Scream:Play()
            script.Parent.HumanoidRootPart.Steps:Stop()
        wait (2)
            script.Parent.HumanoidRootPart.Steps:Stop()
        script.Parent.HumanoidRootPart.Scream:Stop()
        script.Parent.Base.PointLight.Range = 0 
            script.Parent.Base.PointLight2.Range = 0
            wait (3)
            script.Parent.HumanoidRootPart.Anchored = false
            script.Parent.Humanoid.WalkSpeed = 6 
            script.Parent.V.Value = 1
        wait (3)
    end
end
end 

EDIT: I forgot that return would stop it. I added an if statement to check when it loops.

0
i like this. User#19524 175 — 5y
0
You can also make the while loop `while not pause do` instead of having constant return statements? T0XN 276 — 5y
0
I tested that out, and when I changed the value and put it back, it didn't loop anymore. popeeyy 493 — 5y
0
Your loop resumes despite using a return statement? saenae 318 — 5y
Ad

Answer this question