How to prevent Exploiters from Execute Humanoid to take damage?

there’s no Damage only Humanoid it self

External Media
local damage = 10
local db = false
local function KnockBack(character)
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(1e8,1e8,1e8)
	bv.Velocity = character.HumanoidRootPart.CFrame.lookVector * 20
	bv.Parent = character.HumanoidRootPart
	game.Debris:AddItem(bv, 0.1)
end
script.Parent.Damage.OnServerEvent:Connect(function(plr, humanoid)
	if db then
		plr:Kick()
		return
	end
	db = true
	humanoid:TakeDamage(damage)
	print(damage)
	wait(0.5)
	if db then
		print("Damage event completed.")
		db = false
	else
		print("Another damage event occurred before completion.")
	end
end)
type or paste code here
1 Like

Humanoid:TakeDamage will replicate from the server. There is no reason to do the damage on the client. Just cut the client out of the damage entirely and damage the player on the server.

1 Like

this is Clientside Projectlie to ask server to fire event to allClients that this player created it Projectlie

type or paste code here
local rs = game:GetService('ReplicatedStorage')
local fire = rs:WaitForChild('Fire')
local remove = game:GetService("Debris")

local db = false

local function KnockBack(character,plr)
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(1e8,1e8,1e8)
	bv.Velocity = character.HumanoidRootPart.CFrame.lookVector * -50
	bv.Parent = character.HumanoidRootPart
	game.Debris:AddItem(bv, 0.1)
end

fire.OnClientEvent:Connect(function(player,ServerChair)
	local chair = ServerChair.PrimaryPart:Clone()
	chair.Position = player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 2
	chair.Parent = workspace.Debris
	
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bv.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * 100
	bv.Parent = chair
	remove:AddItem(bv,.1)
	remove:AddItem(chair,5)
	
	chair.Touched:Connect(function(hit)
		local PlayerOnTouch = game.Players:GetPlayerFromCharacter(hit.Parent)
		if db then return end
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid and hit.Parent ~= player.Character then
			db = true
			script.Parent.Parent.Damage:FireServer(humanoid,PlayerOnTouch)
			KnockBack(humanoid.Parent)
			wait(0.5)
			db = false
		end
	end)
end)
1 Like

The server has to send it to other clients at some point. Just do the damage when the server does that.

1 Like

i created projectlie on all client because of server delaying projectlie

1 Like

As it is client sided, TakeDamage will not affect other players server-wise, you can try running a local server and see how your script behaves.

1 Like

is this what local server does?

1 Like

You can just change the number of players and it will start multiple clients on the same computer, with the server on another window.
Screenshot 2024-04-25 114125

1 Like