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

How do I get this script to also give the gamepass tools when a player respawns?

Asked by 6 years ago

So I have this script for gamepasses, (Yes its a new one using MarketplaceService:UserOwnsGamePassAsync) It works except for when a player resets or gets respawned, it gives it to them, once, never again, how can I make it give the tool every time said player's character respawns? Heres the script.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 4468725  -- Put your ID here

local function onPlayerAdded(player)


    local hasPass = false

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end

    if hasPass == true then

    -- This is what gives the gamepass tools. Make sure you have the stuff added into a folder named "Tools" in "Replicated Storage" as It takes the tools from there.


    local tools = game.ReplicatedStorage:WaitForChild("Tools1")
        for i,v in pairs(tools:getChildren()) do
            if v:isA("Tool") then
                v:Clone().Parent = player:WaitForChild("Backpack")
                v:Clone().Parnet = player:WaitForChild("StarterGear")
            end
        end
        print(player.Name .. " owns the game pass with ID " .. gamePassID)

    end
end


Players.PlayerAdded:Connect(onPlayerAdded)

1 answer

Log in to vote
0
Answered by 6 years ago

1st up: Add

--Script Made by Vissequ

at the bottom.

2nd: in the "if hasPass" event (Line 23) try this:

player.Character.CharacterAdded:Connect(function(character)
game.ReplicatedStorage.Tools.YourToolNameHere:Clone().Parent = game.Players.LocalPlayer.Backpack
0
Well, uh, I contacted a few people on this at line 30, theres a typo, the script already had that function O.o ResoluteAyres 6 — 6y
Ad

Answer this question