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)
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
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)