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

How do I create a gamepass that gives a player a tool every time they spawn?

--My code is:

local id = 6485848 local barret = game.ServerStorage:FindFirstChildOfClass("Tool")

game.Players.PlayerAdded:Connect(function(player) if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId,id) then local barretClone = barret:Clone() barretClone.Parent = player:WaitForChild("Backpack") end end)

--This script only adds the tool only when the player enters the game, not when they spawn. I tried using CharacterAdded but that is not a child of players, any suggestions?

1 comment

0

That only fires once per session, do character added, it says it's not a child of players because you did it wrong

1 answer

try this script, place it in the ServerScriptStorage

local gpid = 6331302 -- Gamepass ID
tools = {"HasSpeedPassBool"} --Tool Name, place the item in a tool in the ServerStorage
 
GPS = game:GetService("GamePassService")
GPS2 = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
	if char:FindFirstChild("Humanoid") ~= nil then
		print("Has humanoid")
		if GPS2:UserOwnsGamePassAsync(player.UserId,gpid) then -- this is for the new gamepass gpid, not the old assetid
			for _,v in pairs(tools) do
				if game:GetService("ServerStorage"):FindFirstChild(v) then
					game:GetService("ServerStorage"):FindFirstChild(v):clone().Parent = player.Backpack
				end
			end
			
		else
			print("Not awarding item")
		end
	end
end)
end)

1 comment

0

Thanks man

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