Why wont this work (first time)

Hello everyone and i am making a game with a gym system. What i am trying to do is work on a way so when the player buys 1 minute worth, they have 1 minute till it reaches 0, and 2 minutes worth, 2 minutes etc. This works fine for me and players that have bought it before, but for first times (or just on certain occasions) the time doesn’t go down and just stays the same. Is their a flaw in this script that might cause that?

script

local gymtimeactive = {}

game.Lighting.GUIRemotes.GymPayout.OnServerEvent:Connect(function(player,length,cost)
	
	player.Stats.Yen.Value = player.Stats.Yen.Value - cost
	
	player.Stats.GymTime.Value = player.Stats.GymTime.Value + length
	
end)

game.Players.PlayerAdded:Connect(function(player)
	wait(5)
	if player.Stats.GymTime.Value > 0 then	
		player.Stats.GymTime.Value = player.Stats.GymTime.Value -1
		gymtimeactive[player] = true
	while true do
		wait(60)
		if player.Stats.GymTime.Value > 0 then
				player.Stats.GymTime.Value = player.Stats.GymTime.Value -1
				
				else
				
				gymtimeactive[player] = false
				break
			end	
		end
	end
end)


game.Lighting.GUIRemotes.GymPayout.OnServerEvent:Connect(function(player,length,cost)

	if gymtimeactive[player] == nil then

		gymtimeactive[player] = true

	wait(3)
		while player.Stats.GymTime.Value > 0 do

			wait(60)
			if player.Stats.GymTime.Value > 0 then

			player.Stats.GymTime.Value = player.Stats.GymTime.Value -1
			else
				gymtimeactive[player] = false
			break
			end	
		end	
	end
end)

Feel free to ask aditional questions

1 Like

Do you have a error in your console when this happening ? If Yes, please send it.

Also, RemoteEvent go normally on ReplicatedStorage not Lighting. Your RemoteEvent is also exploitable by exploiter because your trust the Client, a exploiter can just call the RemoteEvent "GymPayout"(0,999999)" and i will lose 0 money, and get a lot of GymTime. The verification of money or player data allowing purchases should be verified on the server and not on the client.
I hope this advice will be useful to you

1 Like

ah thank you, and i put them in lighting so exploiters have a harder time finding them. and i think i found the error, up their when the player joins im setting it to nil but down their im testing if it is false

oposite way around. When the player joins im setting it to false and im testing for nil sorry

also its hard to test for an error in the console since it seems to only happen to new people who just joined

Actually exploiter will not relly having hard time to found it because of multiple exploit like “Dex” (these a kind of a copy of the Explorer function on roblox Studio) and another that get all the RemoteEvent send by the client (i have forget the name). They can also simply read the LocalScript

hmm. I process damage values and stats in my local script, but i plan to set up an extra security in server script. One in local script because i want it to only fire once the player meets a certain requirement, but those are in local script and can be exploitable so a second one is in place in the server script to actually validate the firing, is this a good idea?

try to play on “client server” for trying your script

I think you should ask the client to send the amount of GymTime they want and check how much it costs and the rest on the server side. LocalScript checks will be unnecessary to use them with minimal experience but can still block some banal test, personally I would not do for this type of system

hmm i tried on client servers and it works (not sure if its because of data stores)

i will try again and this time ill use data stores 2 since its basically a fresh store so i can see what its like just starting

hmm now its working completely fine i wonder whats going on

don’t forget to close this form if your problem is solved, this will remove it form list
Just click on the “Solution” button

They can even do a negative amount so they can get more money.