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

Why isn't this gamepass tool script give tools after player resets?

Asked by 5 years ago

Hello,

I made this script to give a tool to a player if they own a gamepass when they join the game. That part works fine. The problem is that if the player resets, they don't get the tool back. I tried to use a PlayerAdded event, but it doesn't seem to work.

Here is my script:

game.Players.PlayerAdded:Connect(function(plr)
    local ID = plr.UserId
    wait()
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(ID, 4726509) then
     plr:WaitForChild("Backpack",50)
     local boomclo = game.ServerStorage.Tools.BoomBox:Clone()
     boomclo.Parent = plr.Backpack
    plr.CharacterAdded:Connect(function(char)
         local boomclo = game.ServerStorage.Tools.BoomBox:Clone()
     boomclo.Parent = plr.Backpack
    end)
else
print("No gamepass!")
end
end)

Help would be appreciated.

Thanks!

0
That was a poorly worded title I am now realizing. bluestreakejjp 41 — 5y

3 answers

Log in to vote
1
Answered by 5 years ago

To make sure the player doesn’t lose the tool on death, place the clone in StarterGear as well.

boomclo:Clone().Parent = plr.StarterGear
0
Thanks bluestreakejjp 41 — 5y
Ad
Log in to vote
0
Answered by
vkax 85
5 years ago
Edited 5 years ago

Reason is, you aren't waiting for the backpack, that's the reason it's not working. Here is a fix:

game.Players.PlayerAdded:Connect(function(plr)
repeat wait() until plr.Backpack
   local ID = plr.UserId
        if game:GetService("MarketplaceService"):PlayerHasPass(ID, 4726509) then
         local boomclo = game.ServerStorage.Tools.BoomBox:Clone()
         boomclo.Parent = plr.Backpack
    end
    end)

P.S. I made it a bit smaller :P

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

You can use a character added event

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(character)
        local ID = plr.UserId
        wait()
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(ID, 4726509) then
            plr:WaitForChild("Backpack",50)
            local boomclo = game.ServerStorage.Tools.BoomBox:Clone()
            boomclo.Parent = plr.Backpack
        end
    end)    
end)

Use that instead. Add the character added up at the top after playeradded. Character added fires when a player first spawns or respawns. Adding it at the top will make everything inside the character added event repeat everytime they respawn.

CharacterAdded

Answer this question