Not kicking player

Hello Developers, I’m making a hitbox and I wanted to make something like getting kicked when the size of the hitbox has been changed. But when I change the size manually its not kicking the player. Help please.

Code:

-- Get Needs
local Part = Instance.new('Part')
local Connector = Instance.new('Motor6D')
--

-- Needed Code
game:GetService('Players').PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Box = Part:Clone()
		-- Config Box
		Box.Name = 'Hitbox'
		Box.Size = Character.Torso.Size
		Box.Parent = Character
		Box.CFrame = Character.Torso.CFrame
		Box.CanCollide = false
		-- Config Connector
		Connector.Name = 'BoxConnector'
		Connector.Parent = Character.Torso
		Connector.Part0 = Character.Torso
		Connector.Part1 = Box
		-- Size Detect
		Box.Changed:Connect(function()
			if not Box.Size ~= Character.Torso.Size then
				Player:Kick('Exploiting Detected. Changing hitbox size')
			end
		end)
		--
	end)
end)
--

In this part right here - you are canceling out the not statement and the ~= statement. Try just doing

if Box.Size ~= Character.Torso.Size then
1 Like

Now it kicks me when I spawn in.

Replace with

Box.Changed:Connect(function()
    if Box.Size ~= Character.Torso.Size then
		Player:Kick('Exploiting Detected. Changing hitbox size')
	end
end)

Basically you were saying “if Box.Size is equal to Character.Torso.Size then” this was happening because you had “not” after “then” and you also had ~= (not equal to) instead of == (equal to)

1 Like

Use :GetPropertyChangedSignal

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hitBox = -- Stuff
		
		hitBox:GetPropertyChangedSignal("Size"):Connect(function()
			player:Kick()
		end)
	end)
end)
1 Like

This should do the trick:

-- Detect Hitbox Exploit Script
game:GetService('Players').PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		--Get HumanoidRootPart
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		
		-- Config Box
		local Box = Instance.new('Part')
		Box.Name = 'Hitbox'
		Box.Size = HumanoidRootPart.Size
		Box.Parent = Character
		Box.CFrame = HumanoidRootPart.CFrame
		Box.CanCollide = false
		
		-- Config Connector
		local Connector = Instance.new('Motor6D')
		Connector.Name = 'BoxConnector'
		Connector.Parent = HumanoidRootPart
		Connector.Part0 = HumanoidRootPart
		Connector.Part1 = Box
		
		-- Size Detect
		Box:GetPropertyChangedSignal("Size"):Connect(function()
			if Box.Size ~= HumanoidRootPart.Size then
				Player:Kick('\n\nExploiting Detected: Changing hitbox size\n')
			end
		end)
		
	end)
end)
1 Like

Still doesn’t kick me sadly. Thank you though

You need to change the size from the server. That’s how client-server communication works.


Its a server script.

It’s probably not kicking you because changing the .Size property from the client will not replicate to the server. You probably need to find a different method for this, like checking from the client instead and telling the server that the player needs to be kicked.

2 Likes

It is working as intended. Roblox Client-Server Model. You will need to use a form of remote communication as well as a LocalScript if you want to detect changes on the client however, a smart exploiter could still be able to delete the remote as well as the LocalScript monitoring changes, that will lead us into the whole anti-exploit sector which is more of an advanced complex topic. Remote Functions and Events

So I have to right this code in a client then tell the server to kick the character?

Please go through the article and create some examples. I don’t have the energy to give you a step-by-step guide of what and what not to do but yes, an event firing to the server when a change is detected is more that enough.

Put this into a local script that’s inside StarterPlayerScripts:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

--//Functions
local function detectChanges(character)
	local Box = Character:WaitForChild("Box", 5)
	
	Box:GetPropertyChangedSignal("Size"):Connect(function()
		LocalPlayer:Kick("Exploiter")
	end)
end

detectChanges(Character)

LocalPlayer.CharacterAdded:Connect(function(Character)
	detectChanges(Character)
end)

(Keep in mind this is not secure since it’s a local script)

2 Likes

This can easily be spoofed completely disabling it rending it useless

1 Like

Es my first time scripting something like ngl :sob: yall throwin it at me heavily

1 Like

I deal with a similar issue; how I fixed it was by sending a local script in that would check all the parts and make sure they equal the same size as their server side, if not; it would resize it so they can’t manipulate it. The local script then gets deleted from the server side to prevent any form of prevention and ways to stop the script from happening.

When a hitbox is expanded, it’s done so on the client side; so your server sided script can’t detect that… you need to use a RemoteEvent or a RemoteFunction and a local script to check the sizes and return that value to the server.

How would you do that please walk me threw/explain it to me

1 Like

I like your method it worked but, How would I make it more secure?

Have you tried this