Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to add key to RemoteFunction, don't know where to start!?

Asked by 5 years ago

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
0
So you want the key to be randomly generated (preferably at the same time) on both the server and the client, then if they stay the same, to allow the function to continue? SerpentineKing 3885 — 5y
0
Yeah, thats my goal. MicroStud -6 — 5y
0
Actually thinking back, I want there to be a value with a 9 digit string randomly made on the server and the server will have it in the script thing so the client with the gun localscript will have to grab the value and put it in the remote request but since I will encrypt the localscript no exploiter will know how to aquire it MicroStud -6 — 5y
0
the 9-digit code would be generated when the gun is fired, when player joins or just the same for all servers? SerpentineKing 3885 — 5y
View all comments (2 more)
0
For the player, every time it is shot a new random code is made MicroStud -6 — 5y
0
No I will not Killerlol603 -17 — 5y

4 answers

Log in to vote
0
Answered by
B_Iu 31
5 years ago
Edited 5 years ago

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.

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Don't spoonfeed and PlayerAdded isn't a function. User#24403 69 — 5y
0
@incapaxx all you do is criticize (me anyway) SerpentineKing 3885 — 5y
0
Thanks dude, this is really helpful. MicroStud -6 — 5y
Log in to vote
0
Answered by
farizarps 132
5 years ago

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

Log in to vote
-1
Answered by 5 years ago

No I will not

Answer this question