My Script doesn't add to the value every minute

Hello! My script that adds Points, Total points, and time doesn’t work

This is a regular script not a local
Using a regular script for datastore.
Also you have to click a button to enable the script

game.Players.PlayerAdded:Connect(function(player)
    local Points = player:WaitForChild("leaderstats"):WaitForChild("Points⭐")
    local time = player:WaitForChild("leaderstats"):WaitForChild("Time⏲️")
    local TotalPoints = player.TotalPoints
    
    while wait(60) do
        Points.Value +=2 
        TotalPoints .Value +=2 
        time.Value +=1
    end
end)

game.Players.PlayerAdded:Connect(function(player)
    local Points = player:WaitForChild("leaderstats"):WaitForChild("Points⭐")
    local time = player:WaitForChild("leaderstats"):WaitForChild("Time⏲️")
    local TotalPoints = player.TotalPoints
    
    while true do
        task. wait(60)
        Points.Value +=2 
        TotalPoints .Value +=2 
        time.Value +=1
    end
end)

Try using this. Additionally are they any script errors from the console?

1 Like

No there are no errors in the console at all it’s just when I click a button the script Disabled value is set to false the script doesn’t run after a minute

Oops, I made a mistake. Perhaps its an issue with playerJoined? Try this script: (its only an issue with studio i believe)

local isMessedUp = true

local function onJoined(player)
    local Points = player:WaitForChild("leaderstats"):WaitForChild("Points⭐")
    local time = player:WaitForChild("leaderstats"):WaitForChild("Time⏲️")
    local TotalPoints = player.TotalPoints
    
    while wait(60) do
        Points.Value +=2 
        TotalPoints .Value +=2 
        time.Value +=1
    end
end

game.Players.PlayerAdded:Connect(function(player)
    isMessedUp = false
    onJoined(player)
end)

if isMessedUp then
    for _, player in game.Players:GetPlayers() do
        onJoined(player)
    end
end
1 Like

It didn’t work Couldn’t you use a remote event to the script when the button is clicked?

I figured it out myself using a remote event

game.ReplicatedStorage.Add.OnServerEvent:Connect(function(player)
    local Credits = player:WaitForChild("leaderstats"):WaitForChild("Points⭐")
    local time = player:WaitForChild("leaderstats"):WaitForChild("Time⏲️")
    local TotalCredits = player.TotalPoints

    while wait(60/workspace.Baseplate.PointTimeReducer.Value) do
        Credits.Value +=2 * game.Workspace.Baseplate.PointMultiplier.Value
        TotalCredits.Value +=2 * game.Workspace.Baseplate.PointTimeReducer.Value
        time.Value +=1
    end
end)
1 Like