I don't believe mouse enter is a real event for parts.
The simple way to fix this can be to use a Click detector
However now the problem is, it shows the part as if you can click on it. To fix that, simply set the property CursorIcon to rbxassetid://0
This prevents the click detector from changing the icon.
Now we need to script it, the script would be:
01 | handle.ClickDetector.MouseHoverEnter:Connect( function () |
02 | if tool.Parent = = player.Character and placing = = false then |
04 | PlaceBlock.Parent = workspace |
08 | handle.ClickDetector.MouseHoverLeave:Connect( function () |
09 | if placing = = true then |
This script simply puts the block in workspace when the click detector is hovered over and deletes it when it is not.
If you are wanting this script to go in any part with the correct name, you can add the click detectors into that part before this script runs.
However, if you still do not want it to happen with click detectors and it runs on the client, you can choose a different option. You can get the players mouse by doing local Mouse = game.Players.LocalPlayer:GetMouse()
.
You can then watch the mouse to see whenever it hits something. To do this you will be using Mouse.Move and Mouse.Target
The code for this might look something like this:
1 | local Player = game.Players.LocalPlayer |
2 | local Mouse = Player:GetMouse() |
4 | Mouse.Move:Connect( function () |
5 | local Target = Mouse.Target |
This simply watches for when the mouse is moved then checks if there is a target. It will then run what you want it to do (can be an if statement to check if it is the correct part). You can also use Mouse.TargetFilter to filter out parts you don't want the code to run on (must have the same ancestors, e.g. have them all in the same folder) and Mouse.TargetSurface to make it do things depending on what surface of the target the mouse is pointing to.