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

People are getting minutes while not on the game?

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?

1 comment

0

Turns out it was the module script.

2 answers

✓ Accepted answer
  while wait(60) do
        if not plr.Parent then break end
       Minutes.Value += 1
    end

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)

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