I’m new to scripting and I’m trying to make a script that awards a player a badge when they join.
-Here’s The Script
local badge = game:GetService(“BadgeService”)
local player = game:GetService(“Players”)
player.PlayerAdded:Connect(function(player)
badge:AwardBadge(player.UserId, 2343795372069765)
That is because you are using the player variable twice. Do this instead:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
BadgeService:AwardBadge(player.UserId, 2343795372069765)
end)
Also, you should use BadgeService:UserHasBadgeAsync to make sure that it only gives you the badge if you don’t have it. Here is an updated script with it.
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if not BadgeService:UserHasBadgeAsync(player.UserId, 2343795372069765) then
BadgeService:AwardBadge(player.UserId, 2343795372069765)
end
end)