Hi, everytime i generate a part with this script, it doesnt weld that piece to any other object.
The primary focus of this code is the elseif statement. That's where all the welding happens.
Thanks for the help.
local Tool = script.Parent
xSize = 3
ySize = 1
zSize = 5
Mouse = game.Players.LocalPlayer:GetMouse()
newBlock = nil
local Model = Instance.new("Model",workspace)
function createSingleInstance()
-- print(Mouse.Target)
-- print(type(Mouse.Target))
if Mouse.Target.Name == "Baseplate" then
local groundBlock = Instance.new("Part",workspace.Model)
groundBlock.Name = "Block"
groundBlock.Anchored = true
groundBlock.Size = Vector3.new(xSize,ySize,zSize)
groundBlock.Material = Enum.Material.Plastic
groundBlock.Transparency = 1
groundBlock.Position = Mouse.Hit.p
groundBlock.BackSurface = Enum.SurfaceType.Smooth
groundBlock.BottomSurface = Enum.SurfaceType.Smooth
groundBlock.FrontSurface = Enum.SurfaceType.Smooth
groundBlock.LeftSurface = Enum.SurfaceType.Smooth
groundBlock.RightSurface = Enum.SurfaceType.Smooth
groundBlock.TopSurface = Enum.SurfaceType.Smooth
groundBlock.Transparency = .9
wait (.01)
groundBlock.Transparency = .8
wait (.01)
groundBlock.Transparency = .7
wait (.01)
groundBlock.Transparency = .6
wait (.01)
groundBlock.Transparency = .5
wait (.01)
groundBlock.Transparency = .4
wait (.01)
groundBlock.Transparency = .3
wait (.01)
groundBlock.Transparency = .2
wait (.01)
groundBlock.Transparency = .1
wait (.01)
groundBlock.Transparency = 0
elseif Mouse.Target.Name == "Block" then
local newBlock = Instance.new("Part",workspace.Model)
local target = Mouse.Target
newBlock.Name = "Block"
newBlock.Anchored = true
newBlock.Size = Vector3.new(3,3,3)
newBlock.Transparency = 1
newBlock.Position = Mouse.Hit.p -- nearest surface?
newBlock.BackSurface = Enum.SurfaceType.Weld
newBlock.BottomSurface = Enum.SurfaceType.Weld
newBlock.FrontSurface = Enum.SurfaceType.Weld
newBlock.LeftSurface = Enum.SurfaceType.Weld
newBlock.RightSurface = Enum.SurfaceType.Weld
newBlock.TopSurface = Enum.SurfaceType.Weld
--newBlock.CFrame = otherBlock.CFrame * CFrame.new(0, newBlock.Size.Y / 2 + otherBlock.Size.Y / 2, 0)
workspace.Model:MakeJoints()
newBlock.Anchored = false
newBlock.Transparency = .9
wait (.01)
newBlock.Transparency = .8
wait (.01)
newBlock.Transparency = .7
wait (.01)
newBlock.Transparency = .6
wait (.01)
newBlock.Transparency = .5
wait (.01)
newBlock.Transparency = .4
wait (.01)
newBlock.Transparency = .3
wait (.01)
newBlock.Transparency = .2
wait (.01)
newBlock.Transparency = .1
wait (.01)
newBlock.Transparency = 0
end
end
Tool.Activated:Connect(createSingleInstance)
What it looks like in game: https://imgur.com/a/6tYFihh

3 comments
Can't you just use normal Welds or WeldConstraints?
Yep moved to weld constraints and it works well.
You could try Motor6D but you have to manually set the position with cframe.