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