Giving badge to everyone in a server when two parts touch each other

I’m trying to award a badge to players actively in a server when a certain part hits another. The script seems to be correct, but I get an Argument 1 missing or nil message on line 9.
The onPartTouched registers and the print message sends in output properly.

Any thoughts on what’s up?

local part = script.Parent
local otherPart = game.Workspace.katamari
local BadgeService = game:GetService("BadgeService")
local badgeid = 2124896925

local function onPartTouched(otherPart)
	print(part.Name .. " has touched " .. otherPart.Name)
	local players = game:GetService("Players"):GetPlayers()
	BadgeService:AwardBadge(players.UserID, badgeid)
end

part.Touched:Connect(onPartTouched)
1 Like

Why are you indexing a table of players with UserId? That’s probably the issue. You need to loop through the players table one by one.

local part = script.Parent
local otherPart = game.Workspace.katamari
local BadgeService = game:GetService("BadgeService")
local badgeid = 2124896925

local function onPartTouched(otherPart)
	print(part.Name .. " has touched " .. otherPart.Name)
	local players = game:GetService("Players"):GetPlayers()
    for i,v in pairs(players) do
	    BadgeService:AwardBadge(v.UserID, badgeid)
    end
end

part.Touched:Connect(onPartTouched)
1 Like

That’s what I figured I needed to do, thanks.
I am getting a UserID is not a valid member of Player "Players.ControlCoreAngel" error though on line 10?

That’s strange it looks correct. Is the “d” in UserId capitalized in your script? That might be it, set it to lowercase.

Meant to mention this earlier but this was the error! Everything worked out, thanks!

1 Like