Why my health bar does not work

Ok so I have this tower defense game and I added a hover to see the health of the enemy but now for some reason I cant place towers, this is my script for the hover part (since I added this part I cant place towers and there is not errors in the output)

2 Likes

It’s a little hard to see the code since it’s not formatted. Can you paste it instead of screenshotting?

try turning the hover part’s CanCollide property to false, then changing CanQuery to false too, that way the hover part won’t interfere with raycast

(i am assuming the system adds new Parts)

the hover part’s are a rig(dummy)

RunService.RenderStepped:Connect(function()
local result, mousePos = MouseRaycast({towerToSpawn})
if result and result.Instance then
if towerToSpawn then
if result.Instance.Parent.Name == “GroundPlacement” then
canPlace = true
ColorPlaceholderTower(Color3.new(0, 1, 0))
else
canPlace = false
ColorPlaceholderTower(Color3.new(1, 0, 0))
end

		local x = result.Position.X
		local y = result.Position.Y
		local z = result.Position.Z

		local cframe = CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(rotation), 0)
		towerToSpawn:SetPrimaryPartCFrame(cframe)

	else
		hoveredInstance = result.Instance
		mobsAlive = #workspace.Mobs:GetChildren()
		if mobsAlive > 0 then

			local result, mousePos = MouseRaycast()

			if result and result.Instance and mousePos then
				if result.Instance.Parent.Parent and result.Instance.Parent.Parent.Name == "Mobs" then
					HoverOverMob(result, mousePos)
				elseif result.Instance.Parent.Parent.Parent and result.Instance.Parent.Parent.Parent.Name == "Mobs" then
					HoverOverMob(result, mousePos)
				else
					mobHoverGui.Visible = false
				end
			else
				mobHoverGui.Visible = false
			end
		else

			if mobHoverGui.Visible == true then
				mobHoverGui.Visible = false
			end

		end
	end
else
	hoveredInstance = nil
end

end)

yea make every part inside the rig have CanQuery and CanCollide set to false

for _, v in ipairs(rig:GetChildren()) do
    if not v:IsA("BasePart") then continue end
    v.CanCollide = false
    v.CanTouch = false -- lol
    v.CanQuery = false -- with this, rayCast, region3 and the new region3 alternatives won't detect it
end

I just did it and its not working :frowning:

Replace GetChildren with GetDescendants and it should function as intended.

Yeah I try doing it with only one tower and it is not working :confused: