Hello! Im trying to compare a players score to another player but im not sure how because I dont know how to get their scores in the same script
I have this script in ServerScriptService to make a leaderboard:
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Example of a IntValue
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
I add in a player's score using a part with this script inside whenever they touch the part:
local part = script.Parent
local Players = game:GetService("Players")
curplayers = game.Players:GetChildren()
local function givePoints(player)
local playerStats = player:WaitForChild("leaderstats")
local playerPoints= playerStats:WaitForChild("Points")
playerPoints.Value = playerPoints.Value + 10
part:Destroy()
end
local function partTouched(otherPart) -- Gets the player if one touched the part
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
givePoints(player)
end
end
part.Touched:Connect(partTouched)
I have a block welded on the players that whenever that player comes in contact with another player, (i need help with this=>)a script inside the block needs to check which one of those 2 players have the lowest score and kills him. .
This is the script in ServerScriptService that welds the block , which block will have the script inside that checks which player has the most points and kills the one with the lowest:
local charAdded = function(char)
local a = script:WaitForChild('hitbox'):Clone() -- Hitbox should be changed to whatever the part name is
local w = Instance.new('Motor6D')
w.Part0 = char:WaitForChild('UpperTorso') -- Change this to whatever part of the character you wish to weld it to
w.Part1 = a
w.Parent = char['UpperTorso'] -- This should be the same part as above
a.Parent = char
end
game:GetService('Players').PlayerAdded:Connect(function(plr)
if plr.Character then
charAdded(plr.Character)
end
plr.CharacterAdded:Connect(charAdded)
end)
So do you guys have any ideas how i could compare the score of the 2 players?
Thank you SO much for your time!!!!!

5 comments
Thanks for helping! But im getting an error : Workspace.Player1.hitbox.THIS IS THE SCRIPT I CANT MAKE:6: attempt to index nil with 'leaderstats' Could you help me fix it?
Fixed!
wow you re quick! It worked! Thanks so much for being so helpful have a great day!
You too! Enjoy the rest of your morning / evening.
Thank you so much!