Giving badge on touch

Hey everyone, so I’m starting to finish up on my game. It’s an obby, and there are certain parts where I want to reward the player with a badge. I got the awarding player when they join down, but I’m not sure how to make it work when it touches something. Here is my script. I couldn’t find any errors.

local BadgeService = game:GetService("BadgeService")
local id = 2124620845
local badgegive = game.Workspace.BadgeSkeleton

badgegive.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		game.Players.PlayerAdded:Connect(function(plr)
			if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
				BadgeService:AwardBadge(plr.UserId, id)
			end
		end)
	end
end)

not sure if I need to use

local Players = game:GetService("PlayerService")

if any of you have an idea, please let me know! Thanks :))
if you wanted to know, the skeleton is in a group.

13 Likes

You need to say local player = game.Players:GetPlayerFromCharacter(hit.Parent) to define the player.

6 Likes

here is a script that should work:

local BadgeService = game:GetService("BadgeService")
local id = 2124620845
local badgegive = game.Workspace.BadgeSkeleton

badgegive.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		 if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
			BadgeService:AwardBage(plr.UserId, id)
		 end
	end
end)

Also, your problem was, when someone stepped on the part that is supposed to award the badge, anyone that joined after them, would be awarded the badge on join if they didn’t already have it. So, instead, you need to get the player that touched the part and award them the badge.

28 Likes

ohhhh, ok, let me try that out.

3 Likes

That didn’t seem to work. It still doesn’t give the badge. I’m in studio so maybe that might be the problem, not sure what else could be.

2 Likes

Oh, I figured it out, haha, you spelled the awardBadge wrong. Thanks for the help :)))

6 Likes