I am trying to make badges for my game that was made with my friend, but I made the game under my group.
Roblox thinks the badge is not mine or the script does not work
I’ve tried using tutorials on YouTube but they also don’t work.
Here’s the script that I used:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeGiver = script.Parent
local BadgeId = 2131647747 -- Replace 0 with your badge ID.
BadgeGiver.Touched:Connect(function (hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) == false then
BadgeService:AwardBadge(Player.UserId, BadgeId)
return ("Given")
else
return ("Badge already exists.")
end
end)
Try this script, I modified it from BadgeService's documentation:
Make sure this script is in a Part or MeshPart. Not a model!
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeGiver = script.Parent
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function DetectPlayer(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
return Players:GetPlayerFromCharacter(hit.Parent)
end
end
local function onTouched(hit)
local Player = DetectPlayer(hit)
if Player then
awardBadge(Player)
end
end
BadgeGiver.Touched:Connect(onTouched)
local BadgeService = game:GetService("BadgeService")
local BadgeGiver = script.Parent
local BadgeId = 2131647747 -- Replace 0 with your badge ID.
BadgeGiver.Touched:Connect(function (hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not BadgeService:UserHasBadgeAsync(Player. UserId, BadgeId) then
BadgeService:AwardBadge(Player.UserId, BadgeId)
return ("Given")
else
return ("Badge already exists.")
end
end)
They did work for me. Not awarded but the reqard that I set when owning a badge worked. It’s possible to use badges in studio (even ones that come from other games) as long as you have it in your inventory.
I tried using ChatGPT to make a script and here’s the result:
local part = script.Parent -- Assume the script is placed in the part
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player:WaitForChild("Badges"):WaitForChild("NewBadge").Value = true
end
end)
I know that this won’t work but anyone can modify it.