Hackers could give themselves infinite money!?

I am thinking of making a tycoon game and I am new to scripting. I asked AI about my code and it says that hackers or exploiters could give themselves as much money as they wanted. Is this true? Sometimes AI is incorrect. How else would I make a money claim system for a tycoon? It also says my code is deprecated but I’m learning from tutorials that are a couple of years old

local dss = game:GetService("DataStoreService");
local coins = dss:GetDataStore('playercoins');

local storage = game.ReplicatedStorage;
local remotes = storage.remotes;
local owner = game.CreatorId;

local on = game.Players.ChildAdded;
local off = game.Players.ChildRemoved;

on:connect(function(user)
	Instance.new("Folder", user).Name = 'leaderstats';
	local coin = coins:GetAsync(user.UserId);
	if coin then
		Instance.new("NumberValue", user.leaderstats).Value = coin;
	else
		Instance.new("NumberValue", user.leaderstats).Value = 0;
	end
	user.leaderstats.Value.Name = 'Coins';
	
	if owner == user.UserId then
		user.leaderstats.Coins.Value = 999999999999999;
	end
end)

local increase = remotes.claimCash.OnServerEvent;
increase:connect(function(user, value)
	user.leaderstats.Coins.Value = user.leaderstats.Coins.Value + value;
end)

off:connect(function(user)
	coins:SetAsync(user.UserId, user.leaderstats.Coins.Value);
end)
1 Like

The function that gives money isn’t safe because an exploiter can fire increase with any number they want as the value, so they could give themselves infinite money.

1 Like

Ok thank you. I was planning on making a leaderboard so knowing this should make it safer. But how else would I increase it?

1 Like

Can you show me the localscript which fires increase?

1 Like
local claim = nil;
game.ReplicatedStorage.remotes.claimed.OnClientEvent:connect(function(part)
	claim = part;
end)

while task.wait() do
	if claim then
		claim.Touched:connect(function()
			game.ReplicatedStorage.remotes.claimCash:FireServer(tonumber(game.Players.LocalPlayer.PlayerGui.ScreenGui.CashLabel.Text));
		end)
	end
end
1 Like

I was able to fix it by having a another number value on the server under the player for their ‘unclaimed cash’ and it is supposedly good! Thanks for helping.

1 Like

You should break the while loop after it makes the connection because the way it is right now, it’s creating another connection every loop

while task.wait() do
	if claim then
		claim.Touched:connect(function()
			game.ReplicatedStorage.remotes.claimCash:FireServer(tonumber(game.Players.LocalPlayer.PlayerGui.ScreenGui.CashLabel.Text));
		end)
        break
	end
end
1 Like

Thank you. It says it’s a memory leak and is like adding a new listener 120 times a second. Thanks

1 Like

You still shouldn’t let client choose the reward amount he’s claiming

1 Like

That’s true, the argument is pretty useless, but he said he’s using a NumberValue on the server to decide the amount of cash

1 Like

by the last code it doesn’t look like it

1 Like

My post was addressing a different issue so I wasn’t focusing on the argument being sent to the server

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.