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!
What do you want to achieve? Keep it simple and clear!
I want to create a placement system (placing towers)
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.
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!
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)
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 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!