Firing to client makes error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a sort of anti cheat for my Juke’s Towers of Hell fangame, and if the time is 00:00.00 means that it will fire to a local script where it kicks them.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that when I touch the winpad, while the timer says 00:00.00 it will give me an error saying Argument 1 missing or nil

Here is the normal script

local debounce = false
local diff = script.Parent.diff.Value
local KickEvent = game.ReplicatedStorage.KickEvents.PoLP

script.Parent.Touched:Connect(function(t)
	local timea = game.ReplicatedStorage.GetTimerText:InvokeClient(game.Players:GetPlayerFromCharacter(t.Parent))
	if debounce == false then
		local p = game.Players:GetPlayerFromCharacter(t.Parent)
		if p then
			debounce = true
			if timea == "00:00.00" then
				KickEvent:FireClient()
			else
				wait(3)
				debounce = false
			end
		end
	end
end)

and if needed local script inside of the normal script

local player = game.Players.LocalPlayer
local KickEvent = game.ReplicatedStorage.KickEvents.PoLP

KickEvent.OnClientEvent:Connect(function()
	player:Kick("Kicked for beating the tower too early, you have been reported to the auto moderation system.")
	wait(3)
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried finding topics with similiar errors to this but can’t find any.

Any help would be very appreciated.

2 Likes

You aren’t telling the script what client to fire to. I see you have a player value names “p.” You have to specify the player by writing your player variable (in this case, p) inside your script like so:

KickEvent:FireClient(p)
1 Like

Everytime you fire the client, the first argument has to be the player, instead of KickEvent:FireClient() do KickEvent:FireClient(p)

1 Like

I have tried using

KickEvent:FireClient(p)

But it doesn’t give me an error or anything at all, it doesn’t kick me from the game, making me think that the

KickEvent.OnClientEvent:Connect(function()

in local script didnt function at all.

1 Like

Is there any reason you have to fire to the client first before kicking the player? Exploiters could easily disable this.

If you don’t have a reason, I’d suggest getting rid of the local script, and instead of firing to the client, just kick the player from the server.

local debounce = false
local diff = script.Parent.diff.Value

script.Parent.Touched:Connect(function(t)
	local timea = game.ReplicatedStorage.GetTimerText:InvokeClient(game.Players:GetPlayerFromCharacter(t.Parent))
	if debounce == false then
		local p = game.Players:GetPlayerFromCharacter(t.Parent)
		if p then
			debounce = true
			if timea == "00:00.00" then
				p:Kick("Kicked for beating the tower too early, you have been reported to the auto moderation system.")
			else
				wait(3)
				debounce = false
			end
		end
	end
end)
1 Like

Why are you even kicking them from the client-side?
They can simply avoid the packet from being sent to them (the function won’t be executed).

And, I see nothing wrong with your OnClientEvent, so I’m pretty sure it’s not running in a supported place (ex. workspace).

1 Like

I did think to insert a local script inside of the script, because I thought it would’ve kicked everyone in the server(reason being that it said in output server kicked). But I didn’t think of this at all. Anyways thank you for the help with the anticheat!

2 Likes

The reason is above, and it was running inside of workspace. But now the issue is solved, but thank you anyways!

2 Likes

The function FireClient() requires the player instance to be passed as an argument to it, belonging to whichever client you intend to fire.

1 Like

FireClient() requires the player object pertaining to the client being fired to be passed as an argument to it.

1 Like
local players = game:GetService("Players")
local diff = script.Parent:WaitForChild("diff").Value
local repStorage = game:GetService("ReplicatedStorage")
local kickEvent = repStorage:WaitForChild("KickEvents"):WaitForChild("PoLP")
local timerEvent = repStorage:WaitForChild("GetTimerText")
local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		local timer = timerEvent:InvokeClient(player)
		if debounce then
			return
		end
		debounce = true
		if timer == "00:00.00" then
			kickEvent:FireClient(player)
		end
		task.wait(3)
		debounce = false
	end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local kickEvent = repStorage:WaitForChild("KickEvents"):WaitForChild("PoLP")

kickEvent.OnClientEvent:Connect(function()
	player:Kick("Kicked for beating the tower too early, you have been reported to the auto moderation system.")
	task.wait(3)
end)

Is the timer correct by the way? “00:00.00”.

1 Like

Never said it didn’t require one.
And yes, obviously it does.

At least read before you comment, no?
I’m simply saying there is no reason to kick anyone from the client-side, as it can easily be bypassed by exploiters.

And, I see nothing wrong with your OnClientEvent, so I’m pretty sure it’s not running in a supported place (ex. workspace).

The problem was no client was ever fired.

I have tried using

KickEvent:FireClient(p)

But it doesn’t give me an error or anything at all, it doesn’t kick me from the game, making me think that the
KickEvent.OnClientEvent:Connect(function()
in local script didnt function at all.
(Posted by OP).


For you: I said that based on the other comments, as it was already declared he implemented that already.
You should really read everything instead of between the lines, to understand everything.

You won’t get an error, the FireClient() just never takes place. As such the event handler “OnClientEvent” is never fired.

What’s your point here? I only see useless comments from you on almost every thread, not even based on anything I/anyone ever said.
You are probably referring to the solution, which was not a solution at the time I posted my comment.
All I did was ask why he was considering to do this client-sided, and explained why he shouldn’t.


Me: And, I see nothing wrong with your OnClientEvent, so I’m pretty sure it’s not running in a supported place (ex. workspace).

OP: The reason is above, and it was running inside of workspace. But now the issue is solved, but thank you anyways!

It would have worked had he called “FireClient()” correctly.

He did if you READ.

I have tried using

KickEvent:FireClient(p)

p being the player instance, if you didn’t know as you didn’t even bother to read.
Further comments will be ignored as you are currently spamming down this thread with useless comments.

His player object was incorrectly defined. I have fixed that however.

game.Players:GetPlayerFromCharacter(t.Parent) returns the player instance, since t.Parent is the character in this case.