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

Gear Giving Badge script not working for me, can someone test it and explain?

Hello, my friend says his script is working fine.

However, when I test it in my game it doesn't work. Make sure to edit the script to correct variables.

Tell me if it works or what's wrong, thanks.

local badgeID = 2124533582 --Replace the ID With your Badge ID! 
local badgeService = game:GetService("BadgeService")
function onEntered(player)
    wait(1)
    if not badgeService:UserHasBadge(player.UserId, badgeID) then
local gear = game.ServerStorage.SpeedCoil -------Put the name of the gear you have right there so do like ServerStorage.[gearname] but without brackets

game.Players.PlayerAdded:connect(function(plr)
 plr.CharacterAdded:connect(function(chr)
  for i = 1, #players do
   if players[i] == plr.Name then
    gear:Clone().Parent = plr:WaitForChild("Backpack")
   end
  end
 end)
end)

1 comment

0

u should put gears in replicatedStorage as that is the area ment for cloning

1 answer

I have revised your code and it should work (Assuming you have a gear in your ServerStorage called "SpeedCoil", and that you have this code in a normal script in your ServerStorage or Workspace). Comment if it doesn't. I also added explanations to certain lines.

local badgeService = game:GetService("BadgeService") -- You want to reference roblox services first
local badgeID = 2124533582 
function onEntered(player)
	if badgeService:UserHasBadge(player.UserId, badgeID) then
		local gear = game.ServerStorage.SpeedCoil:Clone() -- Here I have made a clone of the gear you want to give the player (Because if you don't clone it, only one player can obtain this gear that was in ServerStorage)
		gear.Parent = player.BackPack
	else print(player.Name .. " does not have this badge: " .. badgeID) end
end

game:GetService("Players").PlayerAdded:Connect(onEntered) -- Idk what you were doing here, but you just need to get the player that enters

(Make sure to hit "View Source" to copy the code correctly)

7 comments

1

u should always use player:WaitForChild("Backpack") , its safer

0

Hello, thank you so much for the revised code! It was very unfortunate when I loaded it up and it didn't work for me.

0

Yes, I made sure the gear is ServerStorage, AND I made sure the badge ID was right. I own the badge, AND the badge on my test game, yet it prints in output, "Player doesn't have the badge ____" <--- Which is the exact badge ID that I have

0

It also Warns: BadgeId '2124533582' is not of type Badge. Please use MarketplaceService:PlayerOwnsAsset instead.

0

You'd have to show me the badge.

0

Try using BadgeService:UserHasBadgeAsync(UserId, BadgeId)

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