I have a script in my server script service that gives someone a gun if they have a certain gamepass but it only gives it to them when they join. When the person resets or dies, they lose the weapon. How do I get the script to run again after this?
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.

1 comment
http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died