How do I run Multiple Scripts at once?

I’m trying to make a script that blurs and shakes the screen at the same time every time F is pressed, but it only activates on the first try
I’ve tried using coroutine wraps also but those would completely break the coroutines. I’m not too familiar with them so I may be doing something wrong. If it helps I am a beginner scripter and pick up coroutines

local bo = coroutine.create (function()
	for i = 1,20 do
		local a = math.random(-100,100)/100
		local b = math.random(-100,100)/100
		local c = math.random(-100,100)/100
		hum.CameraOffset = Vector3.new(a,b,c)
		wait()
	end
	hum.CameraOffset = Vector3.new(0,0,0)
end)

local co = coroutine.create (function()
	game.Lighting.Blur.Enabled = true
	wait(1)
	game.Lighting.Blur.Enabled = false
	ZoomIn:Play()
end)

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return
		
	end
		
	
	if input.KeyCode == Enum.KeyCode.F then
	enabled = not enabled
		wait()
		Skybox.Parent = game.Lighting
		if enabled then
		ZoomOut:Play()
		coroutine.resume(co)
        coroutine.resume(bo)
			TTSound:Play()
			
			wait(0.5) 
-- issues do only lie within to coroutines only playing once, the script still works so any undefined things here like the TTSound:Play() hasnt been pasted for irrelevancy

everything else beyond this wait point works its just the part above that’s the issue. If I’m supposed to use a coroutine.wrap how would I execute it to work?

2 Likes
local bo = function()
	for i = 1,20 do
		local a = math.random(-100,100)/100
		local b = math.random(-100,100)/100
		local c = math.random(-100,100)/100
		hum.CameraOffset = Vector3.new(a,b,c)
		wait()
	end
	hum.CameraOffset = Vector3.new(0,0,0)
end

local co = function()
	game.Lighting.Blur.Enabled = true
	wait(1)
	game.Lighting.Blur.Enabled = false
	ZoomIn:Play()
end

-- then in the input event put this
coroutine.wrap(bo)()
coroutine.wrap(co)()
1 Like

When a coroutine finishes executing it goes to the dead state, so if you resume it again it will do nothing (it is dead). That is why it works only once.

For this to work as you expect you must create as many coroutines as required.

local bo = function()
	for i = 1,20 do
		local a = math.random(-100,100)/100
		local b = math.random(-100,100)/100
		local c = math.random(-100,100)/100
		hum.CameraOffset = Vector3.new(a,b,c)
		wait()
	end
	hum.CameraOffset = Vector3.new(0,0,0)
end

local co = function()
	game.Lighting.Blur.Enabled = true
	wait(1)
	game.Lighting.Blur.Enabled = false
	ZoomIn:Play()
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.KeyCode == Enum.KeyCode.F then
		enabled = not enabled
		wait()
		Skybox.Parent = game.Lighting
		if enabled then
			ZoomOut:Play()
			coroutine.resume(coroutine.create(co))
			coroutine.resume(coroutine.create(bo))
			TTSound:Play()
			wait(0.5)
		end
	end
end)

You can use coroutine.warp to save some code.

			ZoomOut:Play()
			coroutine.wrap(co)()
			coroutine.wrap(bo)()
			TTSound:Play()
1 Like

thank you it works now, I think what was wrong was the way the locals defined co and bo

1 Like