Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Am I using the RemoteFunction right?

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

✓ Accepted answer

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.

2 comments

1

so what is the _, v for?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.