Script isn't checking for added objects

I’m working on some sort of an anti cheat and I made a script where if it detects a bodygyro or a bodyposition was added, it would kick the objects. But for some reason, it’s not checking for the player. Here’s the code:

HumanoidRootPart.ChildAdded:Connect(function(Object)
	if Object:IsA("BodyGyro") or Object:IsA("BodyPosition") then
		game.ReplicatedStorage.AddWarn:FireServer()
        player:Kick()
	end	
end)

And there are no errors in the output.

Can you show the full code? Keep in mind that events get reset when the player dies as well.

Is this a localscript or a serverscript, where is it stored?

This is the entire code other than the variable to get the local player. This is a local script that is stored in startercharacter scripts.

If you are getting the local player via game.Players.LocalPlayer, it won’t work within a script (which I assume you are using since this is an anti-cheat)

Also, you don’t seem to be using script.Parent.HumanoidRootPart, just HumanoidRootPart

Oh I forgot to mention, that’s a variable too.

Well can you show the full code then? I think it could be helpful

local player = game.Players.LocalPlayer
local character = script.Parent
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

HumanoidRootPart.ChildAdded:Connect(function(Object)
	if Object:IsA("BodyGyro") or Object:IsA("BodyPosition") then
		game.ReplicatedStorage.AddWarn:FireServer()
	end	
end)

In your original script, you are using player (game.Players.LocalPlayer) which is not available on the server. So player:kick() is invoking kick on a nil value.

To get the palyer, try using game.Players:GetPlayerFromCharacter(character)

It’s not a server script. I told you what type of script it was above.

ohh, sorry.

Also, I don’t think localscripts are effective at stopping exploiters, as they can manually disable them through exploits. As they are client-sided.

But it could work, and anyways, this is the only solution.

I tested it on my side and the condition seems to be met. Try checking the code on the server that accepts AddWarn

1 Like