Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I convert this gamepass item script to if a player has badge, give gear script?

Asked by 7 years ago

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.

0
Can you please tab your code as this will help others read the code. User#5423 17 — 7y
0
Why aren't you using a game.Players.PlayerAdded event and a plr.CharacterAdded event instead of connecting Workspace.ChildAdded? GoldenPhysics 474 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

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. User#5423 17 — 7y
0
Except that p is not a local variable. GoldenPhysics 474 — 7y
0
@GoldenPhysics Exactly. tomas7777 20 — 7y
Ad

Answer this question