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!
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.
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