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!
You shouldn't use a LocalScript when dealing with a PlayerAdded function.
Here's a simple fix.
local BadgeService = game:GetService("BadgeService") local badgeId = 2143097943 game.Players.PlayerAdded:Connect(function(plr) local success, hasBadge = pcall(BadgeService.UserHasBadgeAsync, BadgeService, plr.UserId, badgeId) if not success then warn("Your error message") return end if hasBadge then local Button = plr.PlayerGui:WaitForChild("ScreenGui").Frame.FortressButton Button.Text = "YourText" Button.HasBadge.Value = true end end)
This is a server script in ServerScriptService.