#Need help with a moving script
1 messages · Page 1 of 1 (latest)
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
The black part is the slide out part, well model. I made the script where it suppose to slideout like an animation
** You are now Level 1! **
can i see
the script
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)
Thanks for the help 
np
Wasn’t really a thanks u didn’t help
taylor: gifted power