Hi guys! Can someone help me? I did a block when you touches it you get a badge, but the script doesn’t works, then my friend tried to fix and nothing changes, the print also doesn’t works.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and not game:GetService("BadgeService"):UserHasBadgeAsync(plr.UserId, 4243417087173871)then
local IG = hit.Parent:FindFirstChild("IG")
if IG and IG.Value == true then
game:GetService("BadgeService"):AwardBadge(plr.UserId, 4243417087173871)
print(plr.DisplayName .. " (@" .. plr.Name .. ") Awarded the badge Coconut!")
local humanoid = plr.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Sit = true
end
end
end
end
end)
Make sure the value is in StarterCharacterScripts FIRST, so your script can find your value in the player.
I just noticed that you didn’t wrap your UserHasBadgeAsync. If you don’t wrap it in pcall, your script will break and show no errors in the console.
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(plr.UserId, 4243417087173871)
end)
if success and not hasBadge then
-- continue
end
You could also do the same for the actual badge award section.
local badgeId = 4243417087173871
local badgeService = game:GetService(“BadgeService”)
Then all you would need is;
pcall(badgeService.AwardBadge, badgeService, player.UserId, badgeId) --one line
This would actually cover all cases you’re trying to do now…
That’s the easy part. Should add a debouce here as it will touch it 32 times at warp speed.
Also this should be a script in ServerScriptService not in the part. --too hackable
I know it looks odd, but it’s using the fact it may fail to its advantage, with only one call to badgeService. (Of course, make sure it works)
ServerScript
local touch = workspace:WaitForChild("Touchpart") --wherever this is
local badgeService = game:GetService("BadgeService")
local players = game:GetService("Players")
local badgeId = 4243417087173871
local db = {}
touch.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player or db[player] then return end
db[player] = true
pcall(function()
badgeService:AwardBadge(player.UserId, badgeId)
end)
task.wait(3)
db[player] = nil
end)
--[[ testing
local success, err = pcall(function()
badgeService:AwardBadge(player.UserId, badgeId)
end) print(success and "No error" or "Errored: "..err)
--]]
Hi, have you considered that you already have the badge, and the first time testing this you accidently missed the badge notification? If this is very wrong and the studio playtest players badge database resets every run, excuse me, i dont have a lot of experience in BadgeService yet, i just wanted to reply just in case that is actually the solution. lol