Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

trap taking to long to kill?

so i made a trap with region3 here is the code

local RegionPart = game.Workspace.Level1.Traps.trap.KillArea
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)
RegionPart:Destroy()


while true do
	wait()
	local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			

			local char = part.Parent
			char.Humanoid:TakeDamage(99)
		end
	end
	
end

the problem is it takes to long to kill you so i can run right through the kill area if i want to die i have to stand there for a while i did not put any waits or anything

help would be awesome

1 answer

You should ALWAYS avoid wait()

local RegionPart = game.Workspace.Level1.Traps.trap.KillArea
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)
RegionPart:Destroy()
local db = true

local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
partsInRegion.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if db then
			db = false
			print("humanoid!")
			hit.Parent.Humanoid:TakeDamage(99)
			db = true
		end
	end
end)

2 comments

0

This won't work, you need to loop through the partsInRegion and add a touched event individually.

0

yeah this does not work

This discussion is preserved as it was. New answers, comments, and votes are closed.