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

Why isn't this game pass script not working after the player dies?

I have the script set to give an item as long as they have the gamepass, but after the player dies, the item no longer gets into the player's inventory. Can someone help?

 game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:wait()
        if game:GetService("GamePassService"):PlayerHasPass(player, --------) then
            game.ReplicatedStorage:FindFirstChild("Weapon3"):Clone().Parent  = player.Backpack
            game.ReplicatedStorage:FindFirstChild("Weapon3"):Clone().Parent  = player.Backpack
        end
    end)

1 answer

✓ Accepted answer

The code you have will only run once as you do not connect a CharacterAdded event which fiires when the character spawns / respawns.

Connecting the event will resolve this problem,e.g:-

game.Players.PlayerAdded:connect(function(player)
       player.CharacterAdded:Connect(function(charModel)
		-- wait for backpack as it may take a small mount of time to be created when the player joins the game
		player:WaitForChild('Backpack')
	       if game:GetService("GamePassService"):PlayerHasPass(player, --------) then
	           game.ReplicatedStorage:FindFirstChild("Weapon3"):Clone().Parent  = player.Backpack
	           game.ReplicatedStorage:FindFirstChild("Weapon3"):Clone().Parent  = player.Backpack
	       end
	end
   end)

I hope this helps

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