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 convert this gamepass item script to if a player has badge, give gear script?

So, here is the script that awards the player the gear if they have a GAMEPASS

wait(2) 

gpid = 1111111111
tools = {"gear"}

GPS = Game:GetService("GamePassService")
function respawned(char)
player = game.Players:FindFirstChild(char.Name)
print("Respawned")
if char:FindFirstChild("Head") ~= nil then
print("A wild player has appeared!")
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)

Anyone know how to edit it to make it so you have a badge, then it awards the gear? Also, if you already know a have badge award gear script, just post it here.

NOTE: The gear needs to be grabbed out of ingame, in a spot such as lighting. Not from the catalog.

2 comments

0

Can you please tab your code as this will help others read the code.

0

Why aren't you using a game.Players.PlayerAdded event and a plr.CharacterAdded event instead of connecting Workspace.ChildAdded?

1 answer

I suppose you want a script that gives the player a gear if they have a badge when they join the game or respawn (if they earn the badge they can use the gear simply by respawning).

badgeid = 123456789 -- id of badge needed
toolstorage = game.ServerStorage -- where to store the gear(s)
tools = {"Gear"} -- names of the tools (you can put as many as you want)

game.Players.PlayerAdded:connect(function(p)
  p.CharacterAdded:connect(function(c)
        if game:GetService("BadgeService"):UserHasBadge(p.userId, badgeid) then
	    for i,v in pairs(tools) do
              local clone = toolstorage:WaitForChild(v):Clone()
              clone.Parent = p.Backpack
            end
        end
  end)
end)

I'm not sure if this works. Please tell me if it does :)

EDIT: Trying to see if I can make it award instantly

EDIT 2: Improved

3 comments

0

This code will not work as p is only defined on line 7 and will not be available on lines 11 and 14 giving an error. You should also not use ChildAdded there are better events available to use.

0

Except that p is not a local variable.

0

@GoldenPhysics Exactly.

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