Hi, I’m Eli. I was making a build tool, because, why not? And encountered a problem. In my code, I move a part to the mouse.hit.p, to show where the brick will get placed. It flies to the camera. Here is my code.
local SelectedValue = script.Parent:WaitForChild("Selected")
local part = nil
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
script.Parent.Equipped:Connect(function()
part = script.Parent:WaitForChild("Selected").Value:Clone()
part.Parent = workspace
part.CanCollide = false
part.Transparency = 0.5
local Hit = Vector3.new(0,0,0)
Mouse.Move:Connect(function()
Hit = Mouse.Hit.p
part.Position = Hit
script.Parent:WaitForChild("SelectionBox").Adornee = part
end)
Mouse.Button1Down:Connect(function()
game.ReplicatedStorage:WaitForChild("PlaceObject"):FireServer(Hit,script.Parent:WaitForChild("Selected").Value)
Mouse.Button1Up:Connect(function()
end)
end)
end)
script.Parent.Unequipped:Connect(function()
script.Parent:WaitForChild("SelectionBox").Adornee = nil
if part == nil then
print("Part is nil!")
else
part:Destroy()
print("Part destroyed")
end
end)