Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

Ad

Answer this question