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

LocalScript that handles controls stops working once you die?

I have a local script inside of StarterPlayerScripts that lets people punch by left clicking. There are zero errors, and when someone dies and respawns, they can't punch anymore. I have no idea why this is happening, but heres the important parts of the code.

UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local char = player.CharacterAdded:Wait()
--all my vars

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and cooldown == false and stunned == false then
--code that makes them punch
	end
end)

char:WaitForChild("Right Arm").Touched:Connect(function(hit)
--code that hurts enemy
	end
end)

char:WaitForChild("Left Arm").Touched:Connect(function(hit)
--code that hurts enemy
	end
end)

Like I said before, there are no errors and everything stops working once you die. Help?

1 answer

✓ Accepted answer

Scripts placed inside StarterPlayerScripts do not reset when a character dies. Because the script doesn't reset, the char variable is still pointing to the old character (which is nil) and it is not updating the char variable with the new character that spawns.

You can fix this by using CharacterRemoving and CharacterAdded and editing what the char variable points to, although you would also need to reestablish your events, or by simply moving your script to StarterCharacterScripts, which I would recommend since your script will work as intended with this change.

1 comment

0

this websites being retarted so can you add me on disc and help me fathawks#7923

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