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 8 years ago

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

01wait(2)
02 
03gpid = 1111111111
04tools = {"gear"}
05 
06GPS = Game:GetService("GamePassService")
07function respawned(char)
08player = game.Players:FindFirstChild(char.Name)
09print("Respawned")
10if char:FindFirstChild("Head") ~= nil then
11print("A wild player has appeared!")
12if GPS:PlayerHasPass(player, gpid) then
13print("Has GPID")
14for i = 1,#tools do
15game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
View all 22 lines...

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 — 8y
0
Why aren't you using a game.Players.PlayerAdded event and a plr.CharacterAdded event instead of connecting Workspace.ChildAdded? GoldenPhysics 474 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 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).

01badgeid = 123456789 -- id of badge needed
02toolstorage = game.ServerStorage -- where to store the gear(s)
03tools = {"Gear"} -- names of the tools (you can put as many as you want)
04 
05game.Players.PlayerAdded:connect(function(p)
06  p.CharacterAdded:connect(function(c)
07        if game:GetService("BadgeService"):UserHasBadge(p.userId, badgeid) then
08        for i,v in pairs(tools) do
09              local clone = toolstorage:WaitForChild(v):Clone()
10              clone.Parent = p.Backpack
11            end
12        end
13  end)
14end)

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

Answer this question