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

Points are given to the player in the leaderboard, but not working?

local intv = 1
local pointsGiven = 1

----------------------------------------------------


function pointGive()
	while wait(intv) do
		for _, player in ipairs(game.Players:GetPlayers()) do
			local leaderstats = Instance.new("Model", player)
			leaderstats.Name = "leaderstats"
			local points = Instance.new("NumberValue", player.leaderstats)
			points.Name = "Points"
			
			if player:FindFirstChild("leaderstats") then
			player.leaderstats.Points.Value = player.leaderstats.Points.Value + pointsGiven
			end
		end
	end
end

game.Players.PLayerAdded:connect(pointGive)

This should show up a column in the leader board saying "Points" and the player should be awarded 1 point every second. This isn't doing what I want it to do. I also want this to save for next time the players join.

1 comment

0

What output are you getting? What debugging have you done?

1 answer

✓ Accepted answer

The problem here is that you already had a leaderboard, and then you where creating a new one, constantly.

Try replacing it with this:

local intv = 1
local pointsGiven = 1

----------------------------------------------------


function pointGive()
    while wait(intv) do
        for _, player in ipairs(game.Players:GetPlayers()) do
            if player:FindFirstChild("leaderstats") then
            player:WaitForChild('leaderstats'):WaitForChild('Points').Value = player.leaderstats.Points.Value + pointsGiven
	    else
	    local leaderstats = Instance.new("Model", player)
            leaderstats.Name = "leaderstats"
            local points = Instance.new("NumberValue", player.leaderstats)
            points.Name = "Points"
            end
        end
    end
end

game.Players.PLayerAdded:connect(pointGive)

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