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

Unable to cast Instance on double error?

At the moment I'm working on a sword for my game, and I ran into a problem with the sword script. When adding a Debris service to my game, the game casts an error in the output saying, "Unable to cast Instance on double".

blade.Touched:connect(function(hit)
	if equipped and character and humanoid and humanoid.Health > 0 and hit and not hit:isDescendantOf(character) then
		local targethumanoid = hit.Parent:FindFirstChild("Humanoid")
		if targethumanoid and targethumanoid.Health > 0 and not hithumanoids[targethumanoid] then
			hithumanoids[targethumanoid] = true
			
			for _, v in pairs(targethumanoid:GetChildren())do
				if v and v.Name == "creator" then
					v:remove()
				end
			end
			local tag = Instance.new("ObjectValue")
			tag.Name = "creator"
			tag.Value = player
			debris:AddItem(3, tag)          --     This is where the output is pointing at
			tag.Parent = targethumanoid
			
			targethumanoid:TakeDamage(damage * combo)
			p.Data.LevelEXP.Value = p.Data.LevelEXP.Value + 10
		end
	end
end)

Thank you for reading this.

1 comment

0

You have the parameters on line 15 switched around.

1 answer

Nvm, I actually found out the line

debris:AddItem(3, tag)

had to be switched to

debris:AddItem(tag, 3)

This may have been switched due to Roblox lua updating since I followed an old tutorial.

1 comment

1

I'd recommend using :Destroy() over :remove() as well; :remove() is deprecated and :Destroy() is more efficient memory-wise.

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