wait(2)
gpid = 1 -- Gamepass ID here.
tools = {"tool1", "tool2", "tool3"} -- Put the tools in Lighting, and their names here.
GPS = Game:GetService("GamePassService")
function respawned(char)
player = game.Players:FindFirstChild(char.Name)
print("Respawned")
if char:FindFirstChild("Head") ~= nil then
print("Player")
if GPS:PlayerHasPass(player, gpid) then
print("Has GPID")
for i = 1,#tools do
game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
end
else
print("No GPID")
end
end
end
game.Workspace.ChildAdded:connect(respawned)
Will this work for giving a character tools if they have a gamepass?
1 answer
In the future if you just want to know if something will work, just test it rather than coming here
This would work only if the Child that entered the workspace was a player - otherwise it would error.
To make this error-proof, use a PlayerAdded event with a CharacterAdded event.
Also, I suggest you use the PlayerOwnsAsset method, as it returns live results from the website while the PlayerHasPass method returns cached results - meaning that you'd have to rejoin the game if you were to buy the gamepass in game.
Additionally, Lighting shouldn't be used for storage - I suggest using ServerStorage.
This script should be in workspace;
--Put your gamepass ID here
local assetId = 000000
-- Put the tools in ServerStorage, and their names here.
local tools = {"tool1", "tool2", "tool3"}
local ms = game:GetService('MarketplaceService')
function giveTools(plr)
if ms:PlayerOwnsAsset(plr,assetId) then
for i = 1,#tools do
local tool = game.ServerStorage:FindFirstChild(tools[i])
if tool then
if not plr.Backpack:FindFirstChild(tool.Name) then
tool:Clone().Parent = plr.Backpack
end
end
end
end
end
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
giveTools(plr)
end)
end)
2 comments
Thanks for the help, the only reason I didn't test it out was because I didn't want to purchase the gamepass(for my game) if I didn't know how to give people perks yet.
You don't have to purchase a gamepass that is created by you. You automatically own it, silly. Same goes for Developer Products.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I'm a beginner at scripting