Idle Players Bypassing Hurt Script

I am working on a project where players have to avoid appearing obstacles. The problem is, players can cheat if they remain idle and bypass the hurting script. Here’s a video of what I’m talking about:


See? I’m remaining completely still and I am not getting hurt. Here’s some code that I wrote:

local hurt = true

script.Parent.Touched:Connect(function(hit)
	if hurt == true then
		hurt = false
		hit.Parent:FindFirstChild("Humanoid")
		hit.Parent.Humanoid:TakeDamage(50)
		wait(1.5)
		hurt = true
	end
end)

How can I hurt idle players? Please let me know in a post if you can! :grin:

I would recommend connecting it to Magnitude AND Touched. So, you can check for touched in the part, and also check for parts/Humanoids that are nearby the part by connecting it to a magnitude check on active player’s characters. If the player is a certain amount above the part, then they will be hurt.
You would use the Player’s service from a script inside the hurting parts. If a player was anywhere a certain stud count (2-3) above the part, you can hurt them.

I’ve never used Magnitude before. Can you show me an example script?

1 Like
local touching = part:GetTouchingParts()

for i,hit in pairs(touching) do
--code
end
3 Likes
local magnitude = (Position1-Position2).magnitude
print(magnitude) --// distance with Pos1 to Pos2 by studs

Use region3 you can check a area for a player and if the player is in the part Humanoid:TakeDamage(Humanoid.Health)
That is how I would of did it if I was you