Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I fix my giving a badge when an NPC dies?

local Players = game:GetService("Players")
local Bird = script.Parent:WaitForChild("Humanoid")
local BadgeService = game:GetService("BadgeService")

local BadgeID = 0 --I haven't made a badge yet

while true do
	if Bird.Died then
		local players = game:GetService("Players"):GetPlayers()
		BadgeService:AwardBadge(players.UserID, BadgeID)
	end
end

When I run this script it says: Argument 1 missing or nil - Server - Script:10 Stack Begin - Studio Script 'Workspace.FenceDimorphodon.Script', Line 10 - Studio - Script:10 Stack End - Studio

Why is it saying that? I'd really appreciate anyone who can help me!

1 answer

in line 9

local players = game:GetService("Players"):GetPlayers()

you get a table with all the players so in line 10

BadgeService:AwardBadge(players.UserID, BadgeID)

you ask for a specific userID from a table that contains all Players, you don't specify which user you want to get the id from

if you want to give the badge to all players you do

for _, player in pairs(players) do
	BadgeService:AwardBadge(player.UserID, BadgeID)
end

2 comments

0

Thanks for the reply but now it says: Workspace.Dimorphodon.Script:9: invalid argument #1 to 'pairs' (table expected, got Instance). Did I do something wrong?

0

could you send the script/edit the one on your post to the new one?

This discussion is preserved as it was. New answers, comments, and votes are closed.