New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
4

No error for my error... Death effect wont follow the script correctly?

Asked by 4 years ago

This works if I do not use wait() but when I add wait, Nothing happens. I do not recieve and error either.

BodyParts = {"Head","Torso",("Left Arm"),("Left Leg"),("Right Arm"),("Right Leg")}--6

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            for i,v in pairs(BodyParts) do
                character[v].Anchored = true
                character[v].CanCollide = false
                wait(0.5)
                character[v]:remove()

       end
        end)
    end)
end)

1 answer

Log in to vote
2
Answered by
adark 5386 Badge of Merit Moderation Voter Community Moderator
4 years ago

What's happening here is that each body part is getting the "death effect" in sequence, rather than all at once like you would like. The easiest (and safest) way to get around this is to use the Debris Service. Specifically, the AddItem method:

for i, v in pairs(BodyParts) do
    character[v].Anchored = true
    character[v].CanCollide = true
    game.Debris:AddItem(character[v], .5)
end
Ad

Answer this question