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

Am I using the RemoteFunction right?

Asked by 10 years ago

So I'm fairly new to it all, so can anyonen help me?

local funct = game:GetService("ReplicatedStorage"):FindFirstChild("Functions")

local player = game.Players.LocalPlayer

function isaCop.OnServerInvoke(player,currentCops)
end

isaCop is the Child of the RemoteFunction named Functions.

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

I'll give you a full example to help spell RemoteFunctions out for you. :)

First of all, always, always, always, store Scripts in the ServerScriptService when you are able to, as in this case. Your probability of having your game exploited drops significantly when you follow this rule.

Here is the code for this example:

--Script in ServerScriptService
local func = Instance.new("RemoteFunction", Game:GetService("ReplicatedStorage"))
func.Name = "isACop"

local cops = {} --I assume this is full of Player names.

func.OnServerInvoke = function(player)
    for _, v in ipairs(cops) do
        if v == player.Name then return true end
    end
    return false
end
--LocalScript in PlayerGui
local func = Game:GetService("ReplicatedStorage"):WaitForChild("isACop")

local isCop = func:InvokeServer()
print(isCop)

The LocalScript will Invoke the RemoteFunction for every Player, every time they respawn. The OnServerInvoke callback function in the Script receives this Invoke for each player, and returns the boolean true or false depending on whether or not the client-that-the-invoke-originated-from's Player is a cop or not. This return is carried back to the LocalScript, setting the isCop value there.

1
so what is the _, v for? TREVOR818730 25 — 10y
0
https://scriptinghelpers.org/questions/5619/what-is-_letter-and-whats-the-difference-between-pair-and-pairs '_' is a valid character for use in variable names in Lua. When used alone, like in that generic for loop, it implies that the value it holds is not going to be used. adark 5487 — 10y
Ad

Answer this question