Parameters breaking

I was scripting a system today and for some reason the parameters were only picking up two I put in there and re using them. It is not picking up the duration parameter I put in. And they are in the correct order.

Server


function BanFunction.OnServerInvoke(Player, Reason, Duration)
	print(Player)
	print(Duration)
	print(Reason)
	local Success, Error = pcall(function() 
		BanStore:SetAsync(tostring(Player.UserId), {BanStart = os.time(), BanDuration = (Duration * secondsInADay), BanReason = Reason});
		print("Bannedt")
	end)
	print(Duration)
	Player:Kick(Duration);
	if not Success then 
		warn("Not successful.")
	end
end

Client

local function onBanButtonClicked()
	if selectedPlayerId ~= nil then
		local playerToKick = game.Players:GetPlayerByUserId(selectedPlayerId)
		if playerToKick then
			banRemote:InvokeServer(playerToKick, kickReason.Text, 1)
			
			print("Banned " .. selectedPlayerId)
		else
			warn("Could not find player to kick.")
		end
	else
		warn("No player selected")
	end
end

The first parameter of RemoteFunction.OnServerInvoke is the player that sent it. You will need to put that in. Also, you definitely should check that they’re an admin so that bad actors can’t ban whoever they want.

Yes, im using this for testing right now its not public. But why is it not picking up the duration? If I try to print the duration it prints the reason.

Because you’re ignoring the “player that sent this” argument that is always passed into OnServerInvoke.

This needs to become:

function BanFunction.OnServerInvoke(PlayerSentBy, Player, Reason, Duration)

Oh it works thanks for the help. I will give you the solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.