Hey guys, I need help trying to get this simple part that highlights a specific area of the ground so that way you can plant seeds in that area, as i'm developing a farming game as a first project. Trouble is that i cannot find a way to simply have the part follow the mouse's position at all times as long as the tool is equipped.
Here's the Code:
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local Seeds = script.Parent
local mousePosX = mouse.X
local mousePosY = mouse.Y
Seeds.Equipped:Connect(function(player)
if mouse.Target == game.Workspace.Baseplate then
local Highlighter = game.ReplicatedStorage.Highlighter:Clone()
Highlighter.Parent = game.Workspace
Highlighter.Anchored = true
Highlighter.Transparency = 0.5
Highlighter.Material = "Neon"
local highlighterPos = Highlighter.Position
Highlighter.CFrame = CFrame.new(highlighterPos) + Vector3.new(mousePosX, mousePosY)
end
end)
Seeds.Unequipped:Connect(function()
local world = game.Workspace
if world:FindFirstChild("Highlighter") then
local Highlighter = game.Workspace.Highlighter
Highlighter:Destroy()
end
end)
I know there's one thing thats missing but i just dont know what it is exactly. Lemme know how you approach this problem. Thanks!
EDIT Heres the latest script as it is right now.
local Player = game.Players.LocalPlayer
local userinputService = game:GetService("UserInputService")
local Seeds = script.Parent
local mouse = Player:GetMouse()
Seeds.Equipped:Connect(function(player)
if mouse.Target == game.Workspace.Baseplate then
local Highlighter = game.ReplicatedStorage.Highlighter:Clone()
---Highlighter.Parent = game.Workspace
Highlighter.Anchored = true
Highlighter.Transparency = 0.5
Highlighter.Material = "Neon"
local function CalculateMousePosition()
local Camera = workspace.CurrentCamera
local Position = userinputService:GetMouseLocation()
local unitRay = Camera:ScreenPointToRay(Position.X, Position.Y + 36, 0)
local rayCal = workspace:Raycast(unitRay.Origin, unitRay.Direction * 100)
return rayCal
end
end
end)
Seeds.Unequipped:Connect(function()
local world = game.Workspace
if world:FindFirstChild("Highlighter") then
local Highlighter = game.Workspace.Highlighter
Highlighter:Destroy()
end
end)
EDIT 2 I found out the solution through the Roblox DevForum and all i had to do was involve the TargetFilter and associate the part.Position with mouse.Hit.Position and add a Vector3.new and now it's functioning PERFECTLY!!!
Thx guys for helping out!

2 comments
Do not use player:GetMouse for new work, it is being superseded by uis
hey Astrosupernuat, not sure if you saw the updated post, just tellin 'ya here so you get notified :)