I am trying to make a build mode where players are able to build their own cars. However, the part placement system, where the transparent part outline is supposed to follow the player’s mouse is constantly zooming in to the camera, then going to where the player’s mouse is pointing at. However, my goal is for the part to go to where the player’s mouse is pointing at as the player drags their mouse around. How can this problem be resolved?
-- Player Variables
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local connects = {}
--Services
local UserInputService = game:GetService("UserInputService")
--GUI Variables
local selected = script.Parent.Selected
local basic = script.Parent.Basic
local part = basic.Part
local wedge = basic.Wedge
local sphere = basic.Sphere
local cylinder = basic.Cylinder
--Tables
local basics = {"Part", "Sphere", "Wedge", "Cylinder"}
--Non-Declared
local instance
script.Parent.Interface:GetPropertyChangedSignal("Visible"):Connect(function()
if script.Parent.Interface.Visible then
connects.mouseMove = mouse.Move:Connect(onMouseMove)
connects.part = part.MouseButton1Click:Connect(onPartClick)
connects.wedge = wedge.MouseButton1Click:Connect(onWedgeClick)
connects.sphere = sphere.MouseButton1Click:Connect(onSphereClick)
connects.cylinder = cylinder.MouseButton1Click:Connect(onCylinderClick)
else
for _, component in pairs(connects) do
component:Disconnect()
end
end
end)
function onMouseMove()
local obj = selected.Value
if table.find(basics, obj) ~= nil then
print(mouse.Hit.p)
instance.Position = mouse.Hit.p
end
end
function createTransparentInstance(object)
local part = Instance.new("Part")
if object == "Part" then
part.Shape = Enum.PartType.Block
elseif object == "Sphere" then
part.Shape = Enum.PartType.Ball
elseif object == "Cylinder" then
part.Shape = Enum.PartType.Cylinder
else
part = Instance.new("WedgePart")
end
part.Parent = workspace
part.Transparency = 0.5
part.Anchored = true
return part
end
function onPartClick()
selected.Value = "Part"
if instance then instance:Destroy() end
instance = createTransparentInstance(selected.Value)
end
function onSphereClick()
selected.Value = "Sphere"
if instance then instance:Destroy() end
instance = createTransparentInstance(selected.Value)
end
function onWedgeClick()
selected.Value = "Wedge"
if instance then instance:Destroy() end
instance = createTransparentInstance(selected.Value)
end
function onCylinderClick()
selected.Value = "Cylinder"
if instance then instance:Destroy() end
instance = createTransparentInstance(selected.Value)
end