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!
StarterGear
as well.boomclo:Clone().Parent = plr.StarterGear
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
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.