Basically what I’m trying to accomplish is to give the player a badge once they reach level 10.
I wrote the code and i don’t see any errors in it, and the output agrees.
This is a script in ServerScriptService
.
local checkpoints = workspace:WaitForChild("Checkpoints")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[stage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == stage.Value + 1 then
stage.Value = stage.Value + 1
--------------------------------------------------END OF STAGE SCRIPT----------------------------------------------------
--------------------------------------------------START OF BADGE SCRIPT--------------------------------------------------
local players = game:GetService("Players")
local badgeService = game:GetService("BadgeService")
players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats:WaitForChild("Stage")
stage.Changed:Connect(function(newValue)
if newValue >= 10 then
badgeService:AwardBadge(player.UserId, 2142498839)
end
end)
end)
end
end
end)
end)
end)