Scripting issue

Hey developers!
While scripting an admin panel I ran into this issue.
When I click the “kick” button, it should kick the player I put in. But that’s not happening. Please help!

LocalScript:

--Variables--
local button = script.Parent
local input = script.Parent.Parent.UserInput
local event = game.ReplicatedStorage.Kick
--Script--
button.MouseButton1Click:Connect(function()
local result = event:InvokeServer(input.Text)
print(result)
if result == "Success." then
button.Visible = false
end
end)

Script:

--Variables--
local admins = {
    ["iamajust"] = 1;
}
local event = game.ReplicatedStorage.Kick
--Script--
event.OnServerInvoke:Connect(function(player, victim)
    if admins[player.Name] then
	    if game.Players:FindFirstChild(victim) then
		    game.Players:FindFirstChild(victim):Kick([[
		    You have been kicked.
		
		    -Kiba Admin
		    ]])
		    return "Success."
	    else
		    return "Fail."
	    end
    end
end)

I would really appreciate it if someone could help me!
Have a nice day, iamajust

When I saw the

input

thing was blue, I changed my variable, but it still doesn’t work. I don’t know if this was even an issue though.

Any errors that have occurred? are any of your prints printing?

1 Like

Oh, thanks for saying.
Since my plugin errors always show on the bottom I didn’t see it at first.
This is the error shown in the output:

22:20:32.795 OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available - Server - KickScript:8

event.OnServerInvoke = function(player, victim)
	if admins[player.Name] then
		if game.Players:FindFirstChild(victim) then
			game.Players:FindFirstChild(victim):Kick([[
		    You have been kicked.
		
		    -Kiba Admin
		    ]])
			return "Success."
		else
			return "Fail."
		end
	end
end
1 Like

Try using a remote event instead.

--Variables--
local button = script.Parent
local input = script.Parent.Parent.UserInput
local event = game.ReplicatedStorage.Kick
--Script--
button.MouseButton1Click:Connect(function()
local result = event:FireServer(input.Text)
print(result)
if result == "Success." then
button.Visible = false
end
end)

--Variables--
local admins = {
    ["iamajust"] = 1;
}
local event = game.ReplicatedStorage.Kick
--Script--
function isInTable(tableValue, toFind)
	local found = false
	for _,v in pairs(tableValue) do
		if v == toFind then
			found = true
            break
		end
	end
	return found
end

event.OnServerInvoke:Connect(function(player, victim)
if isInTable(admins, player.Name) then
	    if game.Players:FindFirstChild(victim) then
		    game.Players:FindFirstChild(victim):Kick([[
		    You have been kicked.
		
		    -Kiba Admin
		    ]])
		    return "Success."
	    else
		    return "Fail."
	    end
    end
end)
1 Like

Thank you so much for your help! I really appreciate it. :smiley:

I just wanted to explain @heII_ish’s code. Your current code is treating a RemoteFunction like an Event. RemoteEvents will use events but RemoteFunctions use Callbacks. They are write-only members of certain objects that take a function.

2 Likes