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

RemoteFunction outputting weird error?

So I have admin commands in my game that I'm creating. One of the commands is a kick command. It starts with a prefix and a command when it fires a remote function then kicks a player. Well, that is what it should be doing in theory, but instead, it just gives me this error: OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available. I would like to know of a fix to this problem. Please help!

[ CLOSED ] Thank you all for answering and I have given you all an upvote for your time!

Server Script:

local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]

Object.OnServerInvoke:Connect(function(player,target)
		if target ~= nil then
				target:Kick("Kicked by administrator.")
		else
		if target == nil then
			warn"> Got command, target is nil."
		end
		end
end)

Local Script: ***** Works Fine *****

-- Code is shortened.

if(string.sub(CommandLine.Text,1,6)) == string.lower("!kick ") then
			local target = string.sub(CommandLine.Text,7)
			print(target)
			game:GetService("ReplicatedStorage").AdminEvents["KE"]:InvokeServer
			(target) -- This is one the same line just spaced it so it was visible.
			CommandLine.Text = ""
		end

3 answers

✓ Accepted answer

Strings don't have a "Kick" method, which is why your code fails.

Try this:

-- Server
local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]

Object.OnServerInvoke = function(player,target)
        target = game.Players:FindFirstChild(target)
        if target ~= nil then
            target:Kick("Kicked by administrator.")
        else
            warn("> Got command, target is nil.")
        end
end)
--Client

if(string.sub(CommandLine.Text,1,6)) == string.lower("!kick ") then
    local target = string.sub(CommandLine.Text,7)
    print(target)
    game:GetService("ReplicatedStorage").AdminEvents["KE"]:InvokeServer(target)
    CommandLine.Text = ""
end

1 comment

0

Thanks! This finally worked. As the end) is not correct in the server I have fixed that but other than that this worked perfectly! Thank you

your defining the OnServerInvoke() as a event not a callback. also your not returning any value if thats what you wanted, use a RemoteEvent instead.

local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]

Object.OnServerInvoke = function(player,target)
        if target ~= nil then
            target:Kick("Kicked by administrator.")
        else
            warn("> Got command, target is nil.")
        end
end)

also why your script isnt working, is because your kicking a string not a player. for this you would use a generic for loop to loop through the players and check if the target string matches to their name.

local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]

Object.OnServerInvoke = function(player,target)
	for i,v in pairs(game.Players:GetPlayers()) do
		if string.match(v.Name,target) then
			v:Kick("Kicked by administrator")
			break
		else
			warn("> Got command, target is nil.")
			break
		end
	end
end)

1 comment

0

I seem to be getting another error: ServerScriptService.Core Admin Events.KE Base:6: attempt to call method 'Kick' (a nil value)

RemoteFunctions are different from RemoteEvents in implementation. They do not connect to an function, they are assigned a function (Terminology may be improper, but it gets the message across). Notice the difference between the definition of mine and your functions:

local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]
local Players = game:GetService("Players")

Object.OnServerInvoke = function(player,target)
	if target then
		target:Kick("Kicked by administrator.")
	else
		warn"> Got command, target is nil."
	end
end)

Two additional notes:

  1. A RemoteFunction is only useful over a RemoteEvent if it needs to RETURN a value to whatever invoked it

  2. This is not a safe implementation, as exploiters can easily send false requests to your RemoteFunction/RemoteEvent in order to kick a target.

Revision:

local File = game:GetService("ReplicatedStorage")
local Object = File.AdminEvents["KE"]
local Players = game:GetService("Players")

Object.OnServerInvoke = function(player,TargetName)
	local Target = Players:FindFirstChild(TargetName)
	if Target then
		Target :Kick("Kicked by administrator.")
	else
		warn"> Got command, target is nil."
	end
end)

If this helped, please give an upvote if you can.

1 comment

0

I know exploiters can access then but the event is named KE is it will take a minute.

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