I’ve been testing this in studio and tried alternate version but I’m still not awarded the badge.
Here is the code:
--Checkpoint10 teleport script
local badgeId = 1854839377882498
local teleportPart = game.Workspace.Checkpoint10:FindFirstChild("SpawnPart")
local part = script.Parent
part.Touched:Connect(function(plr)
local hrp = plr.Parent:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = teleportPart.CFrame + Vector3.new(0, 5, 0)
local leaderstats = plr:FindFirstChild("leaderstats")
local floors = leaderstats and leaderstats:FindFirstChild("Floors")
local Player = game.Players:GetPlayerFromCharacter(plr.Parent)
--give player badge
local character = plr.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local badgeService = game:GetService("BadgeService")
badgeService:AwardBadge(player.UserId, 1854839377882498)
end
end
if floors and floors:IsA("ValueBase") then
floors.Value = floors.Value + 1
end
end
end)
Yeah that does help but I’m still having problems with awarding the player with a badge. I’ve tried to see if this problem is continuous outside of this script by making a welcome badge and it still won’t award the player with the badge.
You’re getting a BasePart from the touch event but not converting it to a Player for the badge call.
I think.. Not even sure how to say that.
local badgeId = 1854839377882498
local teleportPart = workspace.Checkpoint10:FindFirstChild("SpawnPart")
local part = script.Parent
part.Touched:Connect(function(hit)
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if not plr then return end
local hrp = char:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = teleportPart.CFrame + Vector3.new(0, 5, 0)
local floors = plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Floors")
if floors and floors:IsA("ValueBase") then
floors.Value += 1
end
game:GetService("BadgeService"):AwardBadge(plr.UserId, badgeId)
end
end)
Basic check then Award
local BadgeService = game:GetService("BadgeService")
local badgeId = 1380632145263646
game.Players.PlayerAdded:Connect(function(player)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
if success and not hasBadge then
BadgeService:AwardBadge(player.UserId, badgeId)
end
end)
Award or silent error (they own it or it isn’t going to work for a bit anyway )
local BadgeService = game:GetService("BadgeService")
local badgeId = 1380632145263646
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
BadgeService:AwardBadge(player.UserId, badgeId)
end)
end)
Make sure you have studio api enabled, cause that might interfere. Also sometimes studio js doesnt award badges so test it in the actual game outside of studio
Thanks for spotting that out (this might be my sign to get some sleep). This still doesn’t award the player with a badge. Is this a Roblox studio thing or am I doing something wrong(I’ve quadruple checked the Id of the badge along with having API services enabled).
I’ve used this function too. If errors, prints what error it was or where it happen.
local function AwardBadge(player, badge)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badge)
end)
if not success then
warn("Error while checking if player has badge!")
return
end
if not hasBadge then
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badge)
end)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(function()
BadgeService:AwardBadge(player.UserId, badge)
end)
if not awarded then
warn("Error while awarding badge:", errorMessage)
else
print("Awarding badge")
end
end
else
warn("Error while fetching badge info!")
end
end
end