#Need help with a moving script

1 messages · Page 1 of 1 (latest)

finite grove
#

So I am making a Command Truck with a slideout part. Ive been tryn to mess around with just scripts and Motor6D and nothing seems to work. I am using A-Chassis, Everything is welded and still nothing please help me out!!

tropic dragon
#

maybe dont weld everything

#

it might make th whole truck move

finite grove
#

No I got to where I can drive and everything, the only thing that is anchored is the clickpart, the slideout part is welded to the body of the truck

finite grove
#

The black part is the slide out part, well model. I made the script where it suppose to slideout like an animation

river wrenBOT
#

studio** You are now Level 1! **studio

tropic dragon
#

can i see

finite grove
#

The circle is the anchor for the slideout part

#

wym?

tropic dragon
#

the script

finite grove
#

Yeah

#

local TweenService = game:GetService("TweenService")

-- References
local clickDetector = script.Parent
local clickPart = clickDetector.Parent
local slideOut = clickPart.Parent
local mainPart = slideOut:WaitForChild("Main")
local truck = slideOut.Parent
local anchor = truck:WaitForChild("SlideAnchor") -- invisible pivot part

-- Remove existing welds from Main
for _, child in pairs(mainPart:GetChildren()) do
if child:IsA("WeldConstraint") then
child:Destroy()
end
end

-- Create Motor6D to attach Main to SlideAnchor
local motor = Instance.new("Motor6D")
motor.Part0 = anchor
motor.Part1 = mainPart
motor.C0 = anchor.CFrame:Inverse() * mainPart.CFrame
motor.C1 = CFrame.new()
motor.Name = "SlideMotor"
motor.Parent = anchor

-- Function to weld everything inside Main, including models recursively
local function weldAllToMain(parent)
for _, obj in pairs(parent:GetChildren()) do
if obj:IsA("BasePart") and obj ~= mainPart and obj ~= clickPart then
local weld = Instance.new("WeldConstraint")
weld.Part0 = mainPart
weld.Part1 = obj
weld.Parent = mainPart
elseif obj:IsA("Model") then
weldAllToMain(obj) -- recurse into the model
end
end
end

weldAllToMain(slideOut)

-- Store original C0 for Tween
local originalC0 = motor.C0
local slideDistance = 10 -- studs to extend
local slideTime = 2 -- seconds
local extended = false

-- Tween function
clickDetector.MouseClick:Connect(function(player)
local goal = {}
if not extended then
goal.C0 = originalC0 * CFrame.new(slideDistance, 0, 0) -- slide out
else
goal.C0 = originalC0 -- slide back
end
local tween = TweenService:Create(motor, TweenInfo.new(slideTime, Enum.EasingStyle.Linear), goal)
tween:Play()
extended = not extended
end)

finite grove
#

Thanks for the help facewithrollingeyes

tropic dragon
#

np

finite grove
#

Wasn’t really a thanks u didn’t help

tropic dragon