Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
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

Log in to vote
0
Answered by
aviel101 165
2 years ago

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
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? boijuztgotrecked4 7 — 2y
0
could you send the script/edit the one on your post to the new one? aviel101 165 — 2y
Ad

Answer this question