I have a folder in ServerStorage called Essentials. This also has another folder called Currency. Which has the IntValue in it, named Gold. It will kick the Player out when it finds that the Local Value of Gold is different from the Server Value. This is so the game knows when someone has altered the value. The problem is that it still kicks even when the player didnt outright do anything.

When the player joins the server, the server will detect the player joining the game and will clone the Essentials folder and put in inside the Player (game.Players.LocalPlayer). In that same script, it activates a While Loop where the Player's Gold will increase by 5 every 1 second.

--1st Script

local Players = game.Players
local ServerStorage = game.ServerStorage
local ReplicatedStorage = game.ReplicatedStorage

Players.PlayerAdded:Connect(function(Player)
	print(Player.Name,"has joined the game.")
	local Essentials = game.ServerStorage.Essentials:Clone()
	Essentials.Parent = Player
	
	
	wait(3)
	
	while true do
		Essentials.Currency.Gold.Value = Essentials.Currency.Gold.Value + 5
		wait(1)
	end
end)

There is a LocalScript in StarterCharacterScripts that detects a change in the Gold Value and will send a remote event every time.

--LocalScript

local Player = game.Players.LocalPlayer
local Essentials = Player:WaitForChild("Essentials")
local Currency = Essentials:WaitForChild("Currency")
local Gold = Currency:WaitForChild("Gold")
local ReplicatedStorage = game.ReplicatedStorage
local GoldNumber = Player.PlayerGui:WaitForChild("Menu"):WaitForChild("GoldFrame"):WaitForChild("GoldNumber")

Gold.Changed:Connect(function()
	GoldNumber.Text = Gold.Value
	ReplicatedStorage.RemoteEvents.C2S.Misc.GoldUpdate:FireServer(Gold.Value)
end)

The server will receive the Local Gold Value and will see if it is different from the Server Value. If it is, the server will kick the player as the game will assume they altered it themselves.

--2nd Script


local ReplicatedStorage = game.ReplicatedStorage


ReplicatedStorage.RemoteEvents.C2S.Misc.GoldUpdate.OnServerEvent:Connect(function(Player, LocalGold)
	local ServerGold = Player.Essentials.Currency.Gold.Value
	
	if ServerGold == LocalGold then
		--print(Player.Name .."'s gold successfully increased")
		--(Player isn't hacking)
	else--
		print(Player.Name,"may be hacking.")
		Player:Kick("Exploiting Gold")
	end
end)

3 comments

0

Instead of checking it constantly, you could save the value of the gold at the beginning as a clone, and alter that amount every time the player receives cash from the Server. If they want to buy something, use the amount of gold on the server, and not that from the client.

1

Ehh, this whole system is faulty. The exploiter can just delete the local script and boom, no protection against it. You can only effectively make an anti-exploit cheat on the server. Also, you should never have a local script that checks the value of gold, since you never want to trust the client.  So you shouldn’t need to check if the values are different on the server and client 

0

Which line makes the error?