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)
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)