First of all, you forgot an extra "end)"
Second of all your not doing anything with "plr"
Third of all Values don't have values inside of them
Fourth of all your changing startergui
Fifth your concatenating empty strings
With all that in mind, here's new code
local BS = game:GetService("BadgeService")
local Players = game:GetService("Players")
local Part = script.Parent
local Badges = {[0] = true, [1] = true}
local BadgesOwned = {}
local AlreadyCounting = false
local Success, HasBadge, Player, BadgeInfo, AwardedBadge
local HasBadgeFunction = coroutine.wrap(function(Player, BadgeID)
return pcall(function(Player, BadgeID)
return BS:UserHasBadgeAsync(Player.UserId, BadgeID)
end, Player, BadgeID)
end)
local BadgeInfoFunction = coroutine.wrap(function(Player, BadgeID)
return pcall(function(Player, BadgeID)
return BS:GetBadgeInfoAsyncPlayer(Player.UserId, BadgeID)
end, Player, BadgeID)
end)
local AwardBadgeFunction = coroutine.wrap(function(Player, BadgeID)
return pcall(function(Player, BadgeID)
return BS:AwardBadge(Player.UserId, BadgeID)
end, Player, BadgeID)
end)
local function CountBadges(Player)
if not AlreadyCounting then
AlreadyCounting = true
if #BadgesOwned[Player] >= 1 then
Player.PlayerGui.ScreenGui.b.Visible = true
Player.PlayerGui.ScreenGui.Frame.Visible = true
end
Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = string.format("%i/%i", #BadgesOwned[Player], #Badges)
AlreadyCounting = false
end
end
local function InitializeBadgeCount(Player)
coroutine.wrap(function(Player)
BadgesOwned[Player] = {}
for BadgeID, PartOfGame in pairs(Badges) do
Success, HasBadge = HasBadgeFunction(Player, BadgeID)
for Count = 1, 5 do
if Success then
break
end
wait(4)
Success, HasBadge = HasBadgeFunction(Player, BadgeID)
end
if Success and HasBadge and not BadgesOwned[Player][BadgeID] then
BadgesOwned[Player][BadgeID] = true
CountBadges(Player)
end
end
end)(Player)
end
local function GiveBadgesOnTouched(OtherPart)
if Player:FindFirstChild(OtherPart.Parent.Name) then
coroutine.wrap(function(Player)
for BadgeID, PartOfGame in pairs(Badges) do
Success, BadgeInfo = BadgeInfoFunction(Player, BadgeID)
for Count = 1, 5 do
if Success then
break
end
wait(4)
Success, BadgeInfo = BadgeInfoFunction(Player, BadgeID)
end
if Success and BadgeInfo.IsEnabled and not BadgesOwned[Player][BadgeID] then
Success, AwardedBadge = AwardBadgeFunction(Player, BadgeID)
for Count = 1, 5 do
if Success then
break
end
wait(4)
Success, AwardedBadge = AwardBadgeFunction(Player, BadgeID)
end
if Success and AwardedBadge then
BadgesOwned[Player][BadgeID] = true
CountBadges(Player)
end
end
end
end)(Player)
end
end
Players.PlayerAdded:Connect(InitializeBadgeCount)
Part.Touched:Connect(GiveBadgesOnTouched)
1 comment
Thanks for trying to help, sadly it doesn't change the text on the gui.