Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't this gamepass tool script give tools after player resets?

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!

1 comment

0

That was a poorly worded title I am now realizing.

3 answers

✓ Accepted answer

###To make sure the player doesn’t lose the tool on death, place the clone in StarterGear as well.

boomclo:Clone().Parent = plr.StarterGear

1 comment

0

Thanks

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.

CharacterAdded

This discussion is preserved as it was. New answers, comments, and votes are closed.