Function dosent run task.wait()'s

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    im attempting to make a function in a module that handles all of my killstreak phase stuff

  2. What is the issue? Include screenshots / videos if possible!
    everytime i call the function, anything after a task.wait() NEVER gets called

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive tried switching it to just wait(), and calling the function without task.spawn()

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

the module so far:
(Located in ServerScriptService)

local module = {
	GlobalTasks = {}
}
module.KillsUpdate = function(plr)
	local char = plr.Character
	local HRP = char.HumanoidRootPart
	local hum = char.Humanoid
	local function FindTool()
		if char:FindFirstChildOfClass("Tool") then
			return char:FindFirstChildOfClass("Tool")
		elseif plr.Backpack:FindFirstChildOfClass("Tool") then
			return plr.Backpack:FindFirstChildOfClass("Tool")
		end
	end
	local tool = FindTool()
	if tool == nil then
		warn("No Tool!")
	end
	local kills = tool.Kills.Value
	local Overhead = char.Head.Overhead
	Overhead.Label.Text = kills

	local phases = game.ReplicatedStorage.KillstreakPhases
	local phase1 = phases:WaitForChild("Phase1")--5
	local phase2 = phases:WaitForChild("Phase2")--10
	local phase3 = phases:WaitForChild("Phase3")--25
	local phase4 = phases:WaitForChild("Phase4")--50
	local phase5 = phases:WaitForChild("Phase5")--75
	local phase6 = phases:WaitForChild("Phase6")--100
	local phase7 = phases:WaitForChild("Phase7") --250
	local phase8 = phases:WaitForChild("Phase8") --500
	local phase9 = phases:WaitForChild("Phase9") --777 1255
	local phase10 = phases:WaitForChild("Phase10") --1000
	local EquipMod = require(script.BasicEquip)

	local arr = {
		[5] = function() 
			print("5 kills")
			 local function effects()
				local moosic = script.KsMusic:Clone()
				moosic.Parent = HRP
				moosic:Play()
				print("began")
				task.wait(19.5)
				print("waited")
				EquipMod.Basic(phase1,char)
			 end
			local core = task.spawn(effects)
			module.GlobalTasks[plr.Name] = core
		end,
		[10] = function() print("10 kills") 
			if module.GlobalTasks[plr.Name] then task.cancel(module.GlobalTasks[plr.Name]) print("cancel") end
			EquipMod.Unbasic(char)
			--other 10 kills stuff
		end,
		[25] = function() print("25 kills") 

		end,
	}

	local fn = arr[kills]
	if fn then fn() end;

end

return module

why does it just not use the task.wait()'s?

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

the function is
“[5] = function()”
btw

Does began get outputted? What about waited?

Does the script (calling the module) get deleted at any point?

waited dosent, began does

nothing gets deleted either

plus it shouldnt matter anyways because of the task.spawn()

(i think)

Can you please replace the task.wait(19.5) with

for i = 0, 19.5, 0.5 do 
    print(i)
    task.wait(0.5)
end

It should show us at what point it stops.

it prints “0” and nothing else, jsut completley stops

Hm. I try replacing the 0.5 in the code I sent above with something like 0.01.
If it still says only 0, then I’m gonna be quite confused!

well i guess your gonna be confused, cause it still only printing 0 ;-;

If you remove/comment out this line, does it have any effect?

its been commented out thsi whole time actually, and it has no effect, same with it not commented

Hm.

Going back to your original code, can you please put this immediately above the task.wait(), and let me know what the output is?)

local t = 0
game:GetService("RunService").Heartbeat:Connect(function(dt) 
    t += dt
    print(t)
end)

absolutley nothing was printed (assuming since its waiting for next hearbeat)

I’m still not sold on the script not being deleted.
Again before the wait thing, can you please put

script.Destroying:Once(function()
    warn("Script is being destroyed")
end)

Also put that wherever the module script is being called from as well.

the original script is indeed being deleted, but i put the scripts into workspace instead, still breaks, and nothing is printed from the modules

and again, im pretty sure the scripts deleting dont matter because of the task.spawn being used

clarification: the scripts firing is being put into the dummy being killed, witch gets respawned, aka deleted, but instead of lettignt he scripot get deleted, i made the script go into workspace instead, same results. nothing different

Instead of deleting the NPC immediately, if you instead parent it to nil or ServerScriptService does it have any impact?

nope, no difference at all

( character limit text)

Does the Script Deleting warning still fire?

nope, dosent fire, cause the playerhit is going into workspace to prevent it getting deleted (jsut for the purpous of fixing this weird issue)
image_2024-10-03_215700465