Mouse.Hit not detecting Parts [SOLVED]

You can write your topic however you want, but you need to answer these questions:
I am new to Mouse.Hit so I might have done something wrong, feel free to correct me!

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a placement system (placing towers)

  2. What is the issue? Include screenshots / videos if possible!
    The mouse.Hit doesn’t detect anything other than the enemies (also keep in mind that enemies collision group is set to a different group called ‘Enemies’). I want it to detect the floor.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried mouse raycasting but that doesn’t detect anything other than the enemies too. I have looked over developer hub but nothing has helped me.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Code:

RS.RenderStepped:Connect(function()
	if ViewTower then
		mouse.TargetFilter = ViewTower
	end
	local cframe = mouse.Hit.Position
	print((player.Character.PrimaryPart.Position-cframe).Magnitude) -- prints 9000
	if cframe then
		if ViewTower then
			ViewTower:PivotTo(CFrame.new(cframe)*CFrame.new(0,2,0)*CFrame.Angles(0,math.rad(Rotation),0))
		end
	end
end)

Feel free to ask for any more code!
Any help is appreciated! :smiley:

1 Like

i recommend using raycast instead of mouse.hit.pos as there’s more to it.

1 Like

Firstly, renderstepped should be used sparingly as it can have quite an impact on frame rates.

Why can’t you just use an event rather than looped code like this?

-- Local script
local holding = false

tool.Equipped:Connect(function()
holding = true
while holding do
ViewTower:PivotTo(CFrame.new(cframe)*CFrame.new(0,2,0)*CFrame.Angles(0,math.rad(Rotation),0))
task.wait(.01)
end
end)

tool.Unequipped:Connect(function()
holding = false
end)
1 Like

I have found the solution! The problem was that mouse.Hit did not detect the parts with ‘Default’ Collision group so I renamed my map and its descendants to the ‘Map’ collision group and now it works!

Thanks to everyone else for replying!

1 Like

Thanks for replying however I tried this method and had the same bug with mouse.Hit. I tried every possibility and it didn’t seem to work. However, I learnt that collision groups had affected the problem.

Thanks for replying too however this was for a tower placement system so there was no tool required, however thanks for the tip and I will use this in the future. Appreciate it!

Hm, wouldnt a tool be better suited?

Well, if you’re gonna run this code in some sort of loop use stepped/heartbeat because renderstepped should be used sparingly as the docs say:

1 Like

Just am innocent question is this a td game?

Yes this is a TD game, it is my first time working on tower placement systems without using any tutorials.

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