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

How can i put together that two scripts?

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

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.

4 comments

0

i like this.

0

You can also make the while loop while not pause do instead of having constant return statements?

0

I tested that out, and when I changed the value and put it back, it didn't loop anymore.

0

Your loop resumes despite using a return statement?

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