Got this off roblox-wiki yet funnily enough, the part goes in a completely opposite direction to where I want it to go. Please can someone help me to fix? Does not show any errors or anything like that! The script is used after another identicular script but with a different position.
The code: (The code is in a script in a part, I also added some stuff to it for when it is completed it's movements.)
local Part = script.Parent local newPos = Vector3.new(30.976, 6.022, 8.345) local Time = 1 local Increment = 0.5 local Debounce = false local Diff = newPos - Part.Position local Mag = Diff.magnitude local Direction = CFrame.new(Part.Position, newPos).lookVector function MovePart() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Part.CFrame = Part.CFrame + (Direction * Increment) wait( (Time/Mag) * Increment ) end script.Parent.Orientation = Vector3.new(0, -22.18, 0) Part.Position = Vector3.new(30.976, 6.022, 8.345) Debounce = false end game.Workspace.AnimationValues.Jump.Changed:Connect(function() MovePart() end)
If you want to cheat and make things TOO easy, here's a script:
part = script.Parent local goal = {} goal.Position = Vector3.new(30.976, 6.022, 8.345) local Time = 1 local TweenStyle = Enum.EasingStyle.Linear local TweenDirection = Enum.EasingDirection.InOut local tweenInfo = TweenInfo.new(Time, TweenStyle, TweenDirection) local debounce = false workspace.AnimationValues.Jump.Changed:Connect(function() if debounce then return end debounce = true local Animation = game:GetService("TweenService"):Create(part, tweenInfo, goal) Animation:Play() wait(Time) debounce = false end)
Hope this helped!
Replace anything that says position with CFrame... like this:
local Part = script.Parent local newPos = CFrame.new(30.976, 6.022, 8.345) local Time = 1 local Increment = 0.5 local Debounce = false local Diff = newPos - Part.CFrame local Mag = Diff.magnitude local Direction = CFrame.new(Part.Position, newPos).lookVector function MovePart() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Part.CFrame = Part.CFrame + (Direction * Increment) wait( (Time/Mag) * Increment ) end script.Parent.Orientation = Vector3.new(0, -22.18, 0) Part.CFrame = Vector3.new(30.976, 6.022, 8.345) Debounce = false end game.Workspace.AnimationValues.Jump.Changed:Connect(function() MovePart() end)