I am trying to make a code so that when the player’s mouse hovers over a block, another block appears on top of the block. I have put a script into the part. Here is my code:
local ClickDetector = script.Parent.ClickDetector ClickDetector.MouseHoverEnter:Connect(function() game.Workspace.PlantExample.Position = script.Parent end) ClickDetector.MouseHoverLeave:Connect(function() game.Workspace.PlantExample.Position = game.Workspace.PlantExampleStay end)
I have put this code in a script(Not local) in Workspace. Workspace has filtering enabled, disabled.
Here is what my game looks like in the explorer tab:
\/ Workspace Baseplate \/ Placing1 ClickDetector Script (Where my code above is) Part PlantExample PlantExampleStay
You're just getting the part, not the part's position itself...
Change it to this
local ClickDetector = script.Parent.ClickDetector ClickDetector.MouseHoverEnter:Connect(function() game.Workspace.PlantExample.Position = script.Parent.Position end) ClickDetector.MouseHoverLeave:Connect(function() game.Workspace.PlantExample.Position = game.Workspace.PlantExampleStay.Position end)
also PlantExample will go directly inside the script's Parent... so I recommend you offsetting it so it would go directly on top of the object.
game.Workspace.PlantExample.Position = script.Parent.Position + Vector3.new(0 ,5, 0) --Change 5 to your liking, the other values are irrelevant