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

How do I make a script run when someone resets their character?

2 answers

I would recommend using the .Died event as Bucwheed suggested.

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local hum = player.Character:WaitForChild("Humanoid")

hum.Died:connect(function()
	-- insert whatever you want in here
end)

Use characteradded.. something like this.

giveGun = function()
	print('Hi!')
end
game.Players.PlayerAdded:connect(function(p)
	function a(player, id) --So you don't have to redefine a variable all the time
		return game:GetService("GamePassService"):PlayerHasPass(player, id) -- checks if the player has your gamepass
	end
	p.CharacterAdded:connect(function(c) -- this is the part that you needed help with. everytime the character spawns, it continues to the next code block
		if a(p, 364868976) then --no, i just grabbed a id from a random gamepass I looked at
			giveGun() --gives you the gun
		else 
			print('no wep for u :(')
		end
	end)
end)

Humanoid.Died probably wouldn't work because everytime you die, the localscript in StarterPack reloads. Therefore, completely ruining the purpose of using .Died in the first place.

BUT, .Died can also be used to make you drop all weapons that you had on death. Oh, yeah. If you use p.Character:FindFirstChildOfClass("Humanoid").Died in a serverscript, that could work too.. probably.

if I missed something, tell me instead of flaming me. Thanks.

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