I am working on a game that uses Remote Functions which there is no way to not include it. I am afraid of exploits abusing the Remote Function as I am a exploiter myself (in a good way) and I know what could happen and how. What I plan to have is a key that the script has and the server has the key too, the key is regenerated every time the client script in the gun is fired and if the key matches with the server then the function passes through. However if the remote doesn't pass then the client is disconnected from the server and their stats are cleared. I can do the last part but the actual key matching from client to the server is what I have no clue on where to start.
-- Server local ReplicatedStorage = game:GetService("ReplicatedStorage") local coins = Instance.new("RemoteFunction") coins.Parent = ReplicatedStorage coins.Name = "coins" local function onCreatePartRequested(player) game.Players[player.Name].Money.Value = game.Players[player.Name].Money.Value+100 end coins.OnServerInvoke = onCreatePartRequested
I would not recommend adding any sort of key or password as exploiters do have the ability to easily see values passed in remote events and use it themselves. What I'd do instead is from the server check for a requirement that the player needs to have met.
Though, if you do want to carry out with this, you could use math.randomseed(tick()) on the server and send that over to the client using a remote event. Math.randomseed changes the way math.random generates numbers. After doing that, just change the seed to the same thing in the client as well as the server and generate the random numbers for your string.
To generate the string of text you would do something like this (assuming you want it to be all numbers):
math.randomseed(seed) -- seed would be acquired from the server key = "" for i = 1, 9 do addnum = math.random(1,9) key = key..addnum end
Both random numbers should be the same on both the server and the client.
If you need any more help or elaboration, please let me know in the comments.
Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") local coins = ReplicatedStorage:WaitForChild("coins") local check = 0 function coins.OnClientInvoke(code) check = code return code end game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then coins:InvokeServer(check) end end)
The Function to Invoke the Server in my Example is by pressing "R" but this can be adjusted as needed.
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") local coins = Instance.new("RemoteFunction") coins.Parent = ReplicatedStorage coins.Name = "coins" local saved = 0 game.Players.PlayerAdded:Connect(function(player) local money = Instance.new("IntValue", player) money.Name = "Money" end) function coins.OnServerInvoke(player, check) local code = math.random(100000000, 999999999) local new = coins:InvokeClient(player, code) if check == saved and new == code then saved = code player.Money.Value = player.Money.Value + 100 else player:Kick("Exploit") end end
These are my variations of your script included with a Local counterpart.
This should be what you're looking for, if not let me know in the comments and I'll see what I missed.
I added a PlayerAdded Event for testing purposes.
you could have a module script in replicated storage that generates a really long list of random keys
use a variable to keep count, and ask the module for the nth key in the list from both server and client