local model = Instance.new("Model",workspace)
local part = Instance.new("Part",model)
model.PrimaryPart = part
part.CanQuery = false
part.CanTouch = false
part.CanCollide = false
local connection
connection= game:GetService("RunService").Heartbeat:Connect(function()
model:MoveTo(game.Players.LocalPlayer:GetMouse().Hit.p)
end)
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
local anchored_To = workspace:GetPartsInPart(part)[1]
if anchored_To == nil then
return
end
connection:Disconnect()
local position = part.Position-anchored_To.Position
local weld = Instance.new("Weld",anchored_To)
local part = Instance.new("Part",workspace)
part.Anchored = true
part.Material = Enum.Material.Neon
local cast = workspace:Raycast(part.Position,anchored_To.Position-part.Position)
print(cast.Normal)
weld.C0 = CFrame.new(cast.Position)*CFrame.Angles(cast.Normal.X,cast.Normal.Y,cast.Normal.Z)
weld.Part0 = anchored_To
weld.Part1 = part
end)
local model = Instance.new("Model", workspace)
local part = Instance.new("Part", model)
model.PrimaryPart = part
part.CanQuery = false
part.CanTouch = false
part.CanCollide = false
part.Size = Vector3.new(1, 1, 1)
local connection
connection = game:GetService("RunService").Heartbeat:Connect(function()
model:MoveTo(game.Players.LocalPlayer:GetMouse().Hit.p)
end)
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
local rayOrigin = humanoidRootPart.Position
local rayDirection = (mouse.Hit.p - rayOrigin).unit * 500
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if not raycastResult then return end
local hitPosition = raycastResult.Position
local hitNormal = raycastResult.Normal
local newPart = Instance.new("Part", workspace)
newPart.Anchored = true
newPart.Material = Enum.Material.Neon
newPart.Size = Vector3.new(1, 1, 1)
local surfaceCF = CFrame.new(hitPosition, hitPosition + hitNormal)
local rotationCF = CFrame.Angles(0, 0, math.rad(45))
newPart.CFrame = surfaceCF * rotationCF
local weld = Instance.new("Weld", workspace)
weld.Part0 = raycastResult.Instance
weld.Part1 = newPart
weld.C0 = raycastResult.Instance.CFrame:inverse() * newPart.CFrame
end)```