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

Tool gamepass not cloning when player dies? (Help!)

Asked by 5 years ago
Edited 5 years ago

So I have this gamepass where it would clone a boombox (tool) from the ReplicatedStorage into a player's backpack, using a regular script in the ServerScriptService. The script works at first, but if the player respawns, the boombox doesn't clone again. Thank you for reading.

(The actual boombox is in a folder called "tools")

local storage = game:GetService('ReplicatedStorage')
local tools = storage:WaitForChild('tools')
local dir = { 
    {tools.BoomBox}
}

local id = 4171710

game.Players.PlayerAdded:connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then 
        for key, value in pairs(dir) do
        local tab = value
        for t = 1, #tab do


                        wait ()
        local clone = tab[t]:Clone()
                    print("clone")
                    clone.Parent = player:WaitForChild('Backpack')
                    print("clone.Parent")
        end
        end
    else
        print(player.Name .. " doesn't have the boombox. Sad.")
    end
end)

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago

When the player enters there will give a tool, if he dies the tool will disappear. because player.CharacterAdded was not added, code fixed:

local storage = game:GetService('ReplicatedStorage')
local tools = storage:WaitForChild('tools')
local dir = { 
    {tools.BoomBox}
}

local id = 4171710

game.Players.PlayerAdded:connect(function(player)
 player.CharacterAdded:Connect(function(char)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then 
        for key, value in pairs(dir) do
        local tab = value
        for t = 1, #tab do


                        wait ()
        local clone = tab[t]:Clone()
                    print("clone")
                    clone.Parent = player:WaitForChild('Backpack')
                    print("clone.Parent")
        end
        end
    else
        print(player.Name .. " doesn't have the boombox. Sad.")
    end
 end)
end)
0
It worked, thx! TheLionLiar 39 — 5y
0
or just like...put it in startergear, so they spawn with it when the join the game Galicate 106 — 5y
Ad

Answer this question