Basically I have a script (the one show below) and it only works if I have a variable with the UserId…How would I make this work for everyone?
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2127369000
local UserId = 1234567
while true do
wait()
if BadgeService:UserHasBadgeAsync(UserId, BadgeId) then
script.Parent.Text = "Paper"
else
script.Parent.Text = "Haha"
end
end
As I don’t know what type of script you are using I will provide the 2 ways you can get a player instance:
On the client (LocalScript): local player = game.Players.LocalPlayer
On the server (Script): you can get the player instance on join by using the PlayerAdded event which will pass the instance of the player who joined as the callback function’parameter
When you open a Player object, located under Players in the Explorer, you see a Property named UserId, which is what will be used. Using a for loop and the Players service, we can use Players:GetPlayers() to get a table of players on the session.
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeId = 124567
while true do
task.wait(1)
for _, Player in Players:GetPlayers() do -- For each player in Players, do:
if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) then
-- do whatever
end
end
end
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2127369000
while true do
task.wait(1)
for _, Player in Players:GetPlayers() do -- For each player in Players, do:
if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) then
game.StarterGui.ScreenGui.TextButton.Text = "capybara"
end
end
end
If it’s a script, try this (I haven’t tested this out yet)
while wait() do
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2127369000
local UserId = 1234567
local players = game.Players:GetChildren()
for I, v in pairs(players) do
wait()
if BadgeService:UserHasBadgeAsync(v.UserId, BadgeId) then
script.Parent.Text = "Paper"
else
script.Parent.Text = "Haha"
end
end
if it’s a local script try this,
while wait() do
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2127369000
local player = game.Players.LocalPlayer
if BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
script.Parent.Text = "Paper"
else
script.Parent.Text = "Haha"
end
end
Try this script I did not add the text because it is from my game.
wait(5)
local badgeID = 2129433737 --Put your badge id here--
local badgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
wait(1)
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end)
Your system does work. I just like having it all in a local script, so im gonna be using @DemonLordShadox `s way of doing it. Thank you so much for all the help though!