Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable to cast Instance on double error?

Asked by 7 years ago

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.

0
You have the parameters on line 15 switched around. koolkid8099 705 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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
I'd recommend using :Destroy() over :remove() as well; :remove() is deprecated and :Destroy() is more efficient memory-wise. Pyrondon 2089 — 7y
Ad

Answer this question