In my combat script, I have a function that when called, spawns a Instance.new() on the specified player’s humanoid:
local function SpawnInstance(a,b,c,d)
local v = Instance.new(a,b)
v.Name = c
v.Value = true
delay(d,function()
v:Destroy()
end)
end
SpawnInstance("BoolValue",Humanoid,"Name",1)
The problem is, it will only spawn on the humanoid if the script goes like this.
local function SpawnInstance(a,b,c,d)
local v = Instance.new(a,b)
v.Name = c
v.Value = true
wait(d)
v:Destroy()
end
SpawnInstance("BoolValue",Humanoid,"Name",1)
As you may notice, the only difference is in how the script waits before destroying the instance. I am utterly bamboozled. Any ideas?
local DS: DebrisService = game:GetService("Debris")
function spawn(obj_type, par, name, duration)
local obj: obj_type = Instance.new(obj_type)
obj.Name = name
obj.Parent = par
DS:AddItem(obj, duration)
end
Yes, sorry I forgot to mention. That’s what I originally had it as, it didn’t work. I just tried it again after reading your post, still doesn’t spawn the instance on the Humanoid.
it also prints “1” and “2”. All the conditions required to run this code are met, and those same conditions that run a bunch of other code work just fine. I’ll keep digging.