its me again
Alright, so did you know if you ever invoke the client using remotefunctions, your opening up opportunities of exploiters to damage your server? its interesting. not really but ill show you how to prevent this
lets say you have the client, like this
(ignore the remote name lol)
yes, the server will print “Hello, server!”
and the exploiter changes it to this:
this would damage the server, but with this method of safely invoking the client, you will instead get
Oh and it also works if the exploiter infinitely yields the server too. Want to implement this? Ok follow my steps.
- create some variables dude!
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
--safe invoke
local timeoutcount = 0
local timeout = 5
local result = nil
end)
give the client some time to return a value! (Edit timeout value, just dont mess with timeoutcount)
and result will be important, leave it nil, you will know why its important later
- Lets multithread
local urremoteevent = replicatedstorage.urremoteevent
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
--safe invoke
local timeoutcount = 0
local timeout = 5
local result = nil
task.spawn(function()
local som = urremoteevent
end)
end)
this is important, because were gonna check if it can be used or is bad
- Check the type bro! it could be bad or not needed
local urremoteevent = replicatedstorage.urremoteevent
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
--safe invoke
local timeoutcount = 0
local timeout = 5
local result = nil
task.spawn(function()
local som = urremoteevent:InvokeClient(plr)
if typeof(som) == "string" then -- ofcourse, change string with whatever u like
result = som
end
end)
end)
basically checks the type of the result the client gave you, if its not the one you need it will drop it
- Waiting for timeout, we can’t wait all day
local urremoteevent = replicatedstorage.urremoteevent
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
--safe invoke
local timeoutcount = 0
local timeout = 5
local result = nil
task.spawn(function()
local som = urremoteevent:InvokeClient(plr)
if typeof(som) == "string" then -- ofcourse, change string with whatever u like
result = som
end
end)
repeat task.wait(1) timeoutcount += 1 until timeoutcount >= timeout or result ~= nil
end)
This repeat event will yield until timeout count is the same or bigger than the timeout u gave, or until result is not nil(~= nil)
- Finally, do whatever you want with this result.
local urremoteevent = replicatedstorage.urremoteevent
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
--safe invoke
local timeoutcount = 0
local timeout = 5
local result = nil
task.spawn(function()
local som = urremoteevent:InvokeClient(plr)
if typeof(som) == "string" then -- ofcourse, change string with whatever u like
result = som
end
end)
repeat task.wait(1) timeoutcount += 1 until timeoutcount >= timeout or result ~= nil
if result ~= nil then
print(result) -- replace this with whatever u want to do with result
else
plr:Kick("Unexpected behaviour : timeout reached")
end
end)
Were done! now the clever or not exploiters cant mess with ur remotefunction anymore! epic!
Credits to @CodedJer , he made a formatted version to clearly read it.
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local urremoteevent = replicatedStorage.urremoteevent
players.PlayerAdded:Connect(function(plr)
task.wait(2)
local timeoutcount = 0
local timeout = 5
local result = nil
task.spawn(function()
local som = urremoteevent:InvokeClient(plr)
if typeof(som) == "string" then
result = som
end
end)
repeat
task.wait(1)
timeoutcount = timeoutcount + 1
until timeoutcount >= timeout or result ~= nil
if result ~= nil then
print(result)
else
plr:Kick("Unexpected behaviour : timeout reached")
end
end)
Feedback is appreciated