Check for part existence?

Hey! So right now, I’m making a combat system. I’m stumped on how to check if the hitbox part exists without a while true do loop. Is there anything that could help me with this? Here’s the script for reference. I’ve already tried searching for similar problems. Is there something I may have missed when searching?

game.ReplicatedStorage.HitboxEvents.CreateHitbox.OnServerEvent:Connect(function(plr, hitbox)
	if hitbox == 2 then
		local hitboxpart = game.ReplicatedStorage.WeaponHitboxes.Shonai.Slice2:Clone()
		hitboxpart.Parent = game.Workspace
		hitboxpart.CFrame = plr.Character.Torso.CFrame
		hitboxpart.Position = hitbox.Position + Vector3.new(-1,0,-5)
		hitboxpart.Name = "hitbox"
	elseif hitbox == 3 then
		local hitboxpart = game.ReplicatedStorage.WeaponHitboxes.Shonai.Slice3:Clone()
		hitboxpart.Parent = game.Workspace
		hitboxpart.CFrame = plr.Character.Torso.CFrame
		hitboxpart.Name = "hitbox"
	end
end)

You can use FindFirstChild

if parent:FindFirstChild("the hitbox name") then
print("exists")
end

parent would be the parents name of course, it’s not a global

1 Like

I should check every time the remote fires, correct?
Also, wouldn’t Touched only check for a touching player one time if the condition is true? I assume I’m checking for a Touched player after I find a hitbox part. I want the hitbox to last as long as it’s in the workspace.

Yes you would have to check it every time the remote is fired. In that case, if you are not destroying the hitboxes that are in the workspace, it would only be true once. If you want to make a timeout, you should use os.clock() and calculate the time difference