Pcoi94
(Pcoi94)
April 27, 2023, 4:44pm
#1
I want to detect if a player has a badge but it’s isn’t working, here is the part of the code where it not working:
if success then
cash.Value = ds:GetAsync(plr.UserId .. "-Cash")
shard.Value = shard:GetAsync(plr.UserId .. "-Shards")
xp.Value = xp:GetAsync(plr.UserId .. "-XP")
level.Value = level:GetAsync(plr.UserId .. "-Levels")
if BadgeService:UserHasBadgeAsync(plr.UserId, 2144450000) == false then -- there
cash.Value = 500; shard.Value = 0; xp.Value = 0; level.Value = 1
task.wait(1)
BadgeService:AwardBadge(plr.UserId, 2144450000)
if canGiveBetaBadge == true then BadgeService:AwardBadge(plr.UserId, 2144485549); end
end
else warn(errormessage); end
whole script:
can anybody help?
VSCPlays
(VSCPlays)
April 27, 2023, 4:48pm
#2
do you have any errors in the output?
Please put your badge stuff in a pcall function and tell me if you get any errors. When using the badge service you should really use a pcall function.
I have just tried this and it works fine (prints false).
1 Like
Pcoi94
(Pcoi94)
April 27, 2023, 5:14pm
#4
Hi, I did what you said, but it’s doesn’t work, here is the code
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("MondStats")
local BadgeService = game:GetService("BadgeService")
local canGiveBetaBadge = true
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local cash = Instance.new("IntValue", folder)
cash.Name = "Cash"
local shard = Instance.new("IntValue", folder)
shard.Name = "Shards"
local xp = Instance.new("IntValue", folder)
xp.Name = "XP"
local level = Instance.new("IntValue", folder)
level.Name = "Levels"
local data
local success, errormessage = pcall(function()
data = ds:GetAsync(plr.UserId)
end)
if success then
cash.Value = ds:GetAsync(plr.UserId .. "-Cash")
shard.Value = shard:GetAsync(plr.UserId .. "-Shards")
xp.Value = xp:GetAsync(plr.UserId .. "-XP")
level.Value = level:GetAsync(plr.UserId .. "-Levels")
local badgeData
local badgeSucess, badgeErrorMessage = pcall(function()
badgeData = BadgeService:UserHasBadgeAsync(plr.UserId, 2144450000)
end)
if success then
if badgeData == false then
cash.Value = 500; shard.Value = 0; xp.Value = 0; level.Value = 1
BadgeService:AwardBadge(plr.UserId, 2144450000)
if canGiveBetaBadge == true then BadgeService:AwardBadge(plr.UserId, 2144485549); end
end
end
else warn(errormessage); end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
ds:SetAsync(plr.UserId .. "-Cash", plr.DS.Cash.Value)
ds:SetAsync(plr.UserId .. "-Shards", plr.DS.Shards.Value)
ds:SetAsync(plr.UserId .. "-XP", plr.DS.XP.Value)
ds:SetAsync(plr.UserId .. "-Levels", plr.Levels.Cash.Value)
end)
end)
What issue do you have? It just does not work or what? Any errors in the output?
Pcoi94
(Pcoi94)
April 27, 2023, 5:21pm
#6
founded the error, im just brainless but thanks for helping me!
system
(system)
Closed
May 11, 2023, 5:21pm
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.