Never used corutines and idk what im doing

Char:WaitForChild("Humanoid").Died:Connect(function()
	
	task.spawn(MuteAllAudio)
	
	local lPlayer = game.Players.LocalPlayer
	local Character = lPlayer.Character
	local Results = script.Parent.Results
	local Stuff = Character.Stuff
	
	
	if Character:FindFirstChild("PickleName") then
		local PickleName = Character:FindFirstChild("PickleName")
		script.Parent.B.TextLabel.Text = "KILLED BY: "..PickleName.Value
	end
	
	
	game.TweenService:Create(script.Parent.B, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = UDim2.new(0, 0, 0.847, 0)}):Play()
	game.TweenService:Create(script.Parent.T, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = UDim2.new(0, 0, 0, 0)}):Play()
	
	
	
	
	local Run = function()
		Results.PicklesCollected.Visible = true
		task.wait(1)

		local Check = CheckRating(Stuff.PickleCoinsCollected.Value, "PC")
		Results.Sounds[Check]:Play()
		Results.PicklesCollected:FindFirstChild(Check).Visible = true

		task.wait(1)
		Results.PicklesDodged.Visible = true
		task.wait(1)

		local Check = CheckRating(Stuff.PickleDodges.Value, "PD")
		Results.Sounds[Check]:Play()
		Results.PicklesDodged:FindFirstChild(Check).Visible = true

		task.wait(1)
		Results.Time.Visible = true
		task.wait(1)

		local Check = CheckRating(Stuff.TimeSurvived.Value, "TS")
		Results.Sounds[Check]:Play()
		Results.Time:FindFirstChild(Check).Visible = true
	end
	
	local Coru = coroutine.create(Run())
	
	task.wait(5)
	
	
	script.Parent.Door.Close:Play()
	game.TweenService:Create(script.Parent.Door, TweenInfo.new(1.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Position = UDim2.new(0, 0, 0, 0)}):Play()
	task.wait(2)
	script.Parent.Results.Visible = true
	task.wait(0.5)
	script.Parent.Music:Play()
	script.Parent.Door.Close:Play()
	game.TweenService:Create(script.Parent.Door, TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Position = UDim2.new(0, 0, -1, 0)}):Play()
	
	
	task.wait(2)
	
	
	Results.PicklesCollected.Text = tostring(Stuff.PickleCoinsCollected.Value).." Pickles collected."
	--script.Parent.Results.PicklesDodged.Visible = true
	Results.Time.Text = tostring(Stuff.TimeSurvived.Value).." Survived."
	
	
	
	script.Parent.Results.Skip.MouseButton1Down:Connect(function()
		print("ag")
		coroutine.close(Coru)

		Results.PicklesCollected.Visible = true

		local Check = CheckRating(Stuff.PickleCoinsCollected.Value, "PC")
		Results.PicklesCollected:FindFirstChild(Check).Visible = true

		Results.PicklesDodged.Visible = true

		local Check = CheckRating(Stuff.PickleDodges.Value, "PD")
		Results.PicklesDodged:FindFirstChild(Check).Visible = true

		Results.Time.Visible = true

		local Check = CheckRating(Stuff.TimeSurvived.Value, "TS")
		Results.Time:FindFirstChild(Check).Visible = true
	end)
	
	
	coroutine.resume(Coru)
end)

I tried to make an end results screen (Run() function) that you can skip, i thought using a corutine to cancel the reveal sequence and just put all the results on screen. Issue is that the skip button isint even printing at all. And im not sure if im even doing the corutine stuff right either as ive never done it.

Also you can ignore everything above the run function as that all works fine.

1 Like

Will a print statement print before these lines?
If so, try waiting 15 ish seconds and then pressing the skip button again.

i did something and all the sudden it started working, idk what i did though

1 Like

Fyi this here is erroneous:

When you pass a function into a coroutine, or as a parameter to any method in that matter, you do it without the (). This is because these brackets signify executing the code within the function, and the reference turns into what the function returns, even if that something is nothing or nil. In this case, the screenshot above is equivalent to coroutine.create(nil)

So the correction of this line is:

local Coru = coroutine.create(Run)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.