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)
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
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
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?
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