Weird bug with tools

I have recently realized that when a player dies with a tool with a local script that write

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local root = char.HumanoidRootPart

The position of the variable root seems to be the root position of the old character’s humanoid. Any ideas why this happen??? Thanks in advance :DD

1 Like

You need to replace the character with the new one as it is reset when the player dies:

plr.CharacterAdded:Connect(function(newChar) -- runs when player respawns
char = newChar
root = newChar.HumanoidRootPart
end)
2 Likes

Nvm . I just need a delay before I set the variable char . I think it is because plr.Character does not update immediately when the char respawn

sorry but the tools should be a new one when you dies . Ig it works also but it is long. I will still give you the solution check box for you effort :DD

2 Likes

That’s weird, the line plr.Character or plr.CharacterAdded:Wait() ensures that the script gets the player’s character. If plr.Character is nil (or not loaded) then it will proceed to the plr.CharacterAdded:Wait() part, which waits until the character loads

1 Like

I think since the player’s character already loaded into the game, plr.Characer is not nil when the character died so it will pass the first condition without waiting for the new character

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.