After Player Dies They Cant Use Sword

When you die, the sword will disappear from the inventory and the sword wont work. If you die again and spam switch swords if wont disappear from the inventory, but if you do the exact same thing again it wont work. So everything i have tried that has worked, doesnt work once i do the exact thing again.

The tool gets destroyed on death?
If so, put it into StarterGear or StarterPack for testing.

No it doesnt destroy on death im trying something right now

Any errors? Where are you storing this script? Is the script being added to the player every time they spawn or do they always have it?

the script is inside the sword, and no errors or warnings.

1 Like

Can you add prints throughout the script and replicate the error again. See where the prints stop.

Its best to put a unique print under each loop or if statement and anything thay can yield (like :WaitForChild). By “unique” print i just mean dont put “print(“hi”)” for every line cause it will be hard to tell which print is for what.

1 Like

very smart idea, so line 31 where it says

if c:findFirstChild("Sword") and Enabled == true then

is the issue

Now right before that line print(c:findFirstChild(“Sword”)) and print(Enabled). See which (or both) conditions aren’t being met.

it says on the line for the c:findfirstchild(“Sword”) nil which i think means that it doesnt detect the sword. The enabled is true which means that is working as intended.

Can you print(c ). It might be that when the character dies/respawns and you try to use the c variable. It returns nil because its referencing the old character that died and no longer exist. This only applies if the script isn’t being runned every time the player spawns (which is what you said).

If this is the case, the simple solution would be to define the character inside the functions/InputConnection.

Alright ill try it now, hopefully it works

I just tried it and it detects my name still and doesnt return nil.

Oh you might still be able to reference the character even if its deleted. So actually print(c.Parent). If its workspace then its an issue with the sword, if its nil then its the issue i stated above

You were right c.Parent returns nil. How can I fix this if you dont mind me asking?

Just reference the character inside the function/Input connection. So remove the repeat wait and the c variable at the start of the script. Move it so its inside the Button1Down connection and the input connection.

Basically every time those connections are fired, instead of using the old character, you get and define the players current character and use that.

Alright ill try it right now hopefully it works

E.g

UIS.InputBegan:Connect(function(input,typing)
    local c = Player.Character
    if c then
-- continue with everything else
    end
end)

Gotta do the same thing for mouse1button connection too

From what I tested out, it works! Thanks, if i have any more issues ill reply back.

No problem and good luck with your project!

Thanks, and if your working on your own project then I wish you good luck as well.