Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't the part go to the position I want it to go?

Asked by 6 years ago
Edited 6 years ago

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)
0
you're using Vector3s for a CFrame at line 11 loulou1112 35 — 6y
0
^That's totaly fine, but you should use (Part.Position - newPos).Unit instead. RubenKan 3615 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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!

Ad
Log in to vote
0
Answered by 6 years ago

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)
0
Doesn't work, gives out this error: bad argument #2 to '?' (Vector3 expected, got CFrame) willkiller13 43 — 6y

Answer this question