im making a local script that checks if a player has this badge, it does something to a text button if so
this, is the script:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 2143097943
local function onPlayerAdded(player)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
if not success then
warn("Error while checking if player has badge!")
return
end
if hasBadge then
script.Parent.Frame.FortressButton.Text = "FORTRESS"
script.Parent.Frame.FortressButton.HasBadge.Value = true
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
this local script is inside a screengui, and it doesn't work. there is no errors in the output, i tried looking for solutions but cant find one.
any help is appreciated!

3 comments
worked. thanks so much!
LocalScripts can use Players.PlayerAdded, just not to pick up on the local player's connection. This is because the client is already connected to the server, as they had to download the LocalScript to begin with. It's considered a bad practice to manipulate a client's UI on the server, so the proper solution would be to remove Players.PlayerAdded from the LocalScript instead of moving to a Script
yes u can use a remote event, but this is for simplicity's sake