I was trying to make a part called "DisplayPart" follow the mouse every time it moves but it won't I think because of either the Move event or the ray(Line 20-23),why and how do I fix it? I don't have any errors in the output.
Script:
Tool = script.Parent
Handle = Tool.Handle
Player = game.Players.LocalPlayer
Camera = game.Workspace.CurrentCamera
---------------------------------
function CreateDisplayPart()--Creates DisplayPart
local DisPart = Instance.new("Part",Camera)--Hides it from players
DisPart.Anchored = true
DisPart.CanCollide = false
DisPart.Transparency = 0.5
DisPart.Name = "DisplayPart"
end
---------------------------------
Tool.Equipped:connect(function(Mouse)
---------------------------------
DisplayPart = Camera:FindFirstChild("DisplayPart")
if not DisplayPart then--If not found then makes it
CreateDisplayPart()
else
Mouse.Move:connect(function()
local Ray = Ray.new(Mouse.UnitRay.Origin,--Creates ray
Mouse.UnitRay.Direction)
Hit = Workspace:FindPartOnRay(Ray)
if Hit ~= nil then --If not nil then do the following
DisplayPart.Position = Mouse.UnitRay.Direction
end
end)
end
end)

2 comments
I fixed up the script, and added alternative way of doing same thing.
Thanks.