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

Why my script doesn't work?

Here is my script:

function hasPass(player,id) --Creating a simple function to see if the player has the GamePass with that id
 if game:GetService("GamePassService"):PlayerHasPass(player,id) then
  return true
 else 
  return false
 end
end
 


game.Players.PlayerAdded:connect(function(player)
 
 if hasPass(player,163409880) then --We're calling the function
  print(player.Name .. " has the GamePass!")


 elseif game:GetService("BadgeService"):UserHasBadge(p.userId, 93416536) then
        print("The user has this badge")

else
  print(player.Name .. " doesn't have the GamePass")
 end
end)

this script suppose to give player a badge if he got the gampass

1 comment

0

You don't have a connection line to run the hasPass function. Try adding a connection line.

1 answer

✓ Accepted answer

Your code never actually awards a badge! Also you only check if the user has the badge if they don't have the pass, Right code:

function hasPass(player,id) --Creating a simple function to see if the player has the GamePass with that id
 if game:GetService("GamePassService"):PlayerHasPass(player,id) then
  return true
 else 
  return false
 end
end



game.Players.PlayerAdded:connect(function(player)

 if hasPass(player,163409880) then --We're calling the function
  print(player.Name .. " has the GamePass!")


 if game:GetService("BadgeService"):UserHasBadge(p.userId, 93416536) then
        print("The user has this badge")
else
game:GetService("BadgeService")AwardBadge(p.userId, 93416536)
end
else
  print(player.Name .. " doesn't have the GamePass")
 end
end)

1 comment

0

thanks may you fixed it so ill be able to copy it?

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