Is there a better way to do this?

Basically it needs to detect if the firework hits the ring, but both are anchored so I can’t use Touched. I did while true do with a small wait to constantly check but I feel like this is bad practice and could lead to lag. Here’s my current code

local ring = script.Parent
local hitbox = ring.Hitbox
local touch
local amount = 10
local debounce = true
print("c")

while true do
	touch = game.Workspace:GetPartsInPart(hitbox)
	for i, v in pairs(touch) do
		if v.Parent:FindFirstChild("Sound") then
			if debounce == true then
				debounce = false
				local playerName = v.Parent:GetAttribute("Player")
				print(playerName)
				local player = game.Players:FindFirstChild(playerName)
				game.ReplicatedStorage.Remotes.CashEffect:FireClient(player, player, amount*5)
				ring:Destroy()
				break
			end
		end
	end
	wait(0.1)
end

cant you just use a Touched Event on the ring and add a hitbox to the ring since touched works still when Anchored.

Both the firework and the hitbox in the ring are anchored, and no, touched doesn’t work when both are anchored

Use a magnitude check: (ring.Position - firework.Position).Magnitude every RunService.RenderStepped, and use a hit box check using the CheckRegion3d? I forgot* of workspace to check the hitbox.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.