Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

People are getting minutes while not on the game?

Asked by
3F1VE 257 Moderation Voter
2 years ago

Hey there, so apparently in my friends game (I'm the scripter) people are getting minutes even out of game. Here is my minutes giving code :

game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = plr:WaitForChild("leaderstats")
    local Minutes = leaderstats:WaitForChild("Minutes")
    while wait(60) do
        Minutes.Value += 1
        if not plr then break end
    end
end)

I don't know what's wrong but I use a module for making leaderstats (I made it) Here is the modules code :

local module = {}


function module:CreateLeaderstatsForPlayer(Player: Player, Data: {})
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    for index, value in pairs(Data) do
        local Name = value.Name
        local ClassName = value.ClassName
        if not Name then return warn("No Name was provided.") end
        if not ClassName then return warn("No ClassName was provided.") end
        if not string.find(ClassName, "Value") then return warn("Invalid ClassName.") end
        if not (pcall(function() Instance.new(ClassName):Destroy() end)) then 
            return warn("ClassName "..ClassName.."does not exist.")
        end
        local Stat = Instance.new(ClassName)
        Stat.Name = Name
        Stat.Parent = Leaderstats
        Stat.Value = 0 or nil
    end
    return Leaderstats
end

function module:CreateLeaderstatsOnPlayerJoin(Data: {})
    local Players = game:GetService("Players")
    return Players.PlayerAdded:Connect(function(Player)
        local Leaderstats = Instance.new("Folder")
        Leaderstats.Name = "leaderstats"
        Leaderstats.Parent = Player
        for index, value in pairs(Data) do
            local Name = value.Name
            local ClassName = value.ClassName
            if not Name then return warn("No Name was provided.") end
            if not ClassName then return warn("No ClassName was provided.") end
            if not string.find(ClassName, "Value") then return warn("Invalid ClassName.") end
            if not (pcall(function() Instance.new(ClassName):Destroy() end)) then 
                return warn("ClassName "..ClassName.."does not exist.")
            end
            local Stat = Instance.new(ClassName)
            Stat.Name = Name
            Stat.Parent = Leaderstats
            Stat.Value = 0 or nil
        end
    end)
end

return module

I use the first function module:CreateLeaderstatsForPlayer(plr, {data here}) in another script. So can anyone help me here?

0
Turns out it was the module script. 3F1VE 257 — 2y

2 answers

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago
  while wait(60) do
        if not plr.Parent then break end
       Minutes.Value += 1
    end
Ad
Log in to vote
0
Answered by 2 years ago

You could probably use something like this to end the loop when a player leaves

game.Players.PlayerRemoving:Connect(function(plr)
    --end the loop here
end)

Answer this question