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

Why are these VIP items not saving after death?

Asked by 8 years ago

So I have a few scripts that give certain items when you buy certain levels of VIP, and that has worked fine. What I just noticed today is that after I die, I don't keep any of the items, and they only stay in my inventory for the life I join the game in.

The tool is placed into Startergear, so I don't know the problem.

This is the script

local passId = 254941359

local potato = game.Lighting:WaitForChild("VIP")


function isAuthenticated(player) 
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr) -- player is already defined
    if isAuthenticated(plr) then
        print(plr.Name .. " has bought the game pass with id " .. passId)
        potato:Clone().Parent = plr.Backpack
        potato:Clone().Parent = plr.StarterGear
    end
end)

Please respond, this is kind of urgent.

1 answer

Log in to vote
2
Answered by 8 years ago

PlayerAdded is only fired when a player joins the server. Use character added instead so that everytime the player respawns their character is readded to the game and therefore this script will give them their gear back

local passId = 254941359

local potato = game.Lighting:WaitForChild("VIP")


function isAuthenticated(player) 
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr) -- player is already defined
    plr.CharacterAdded:connect(function(Character) --will check when character is readded(cause of death usually) and readd those tools. You can now use Character to reference the character and plr to reference the player
            if isAuthenticated(plr) then
                print(plr.Name .. " has bought the game pass with id " .. passId)
                potato:Clone().Parent = plr.Backpack
                potato:Clone().Parent = plr.StarterGear
        end
end)


0
Thank you, I didn't know what existed. Your script didn't work at first, but it was only because of a missing 'end' SpazzMan502 133 — 8y
0
oh, rip :P, sorry bout that! dragonkeeper467 453 — 8y
Ad

Answer this question