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

Using CFrame, moving a block slowly to a position?

Asked by 4 years ago

I'm pretty new to scripting so I know a few things, but not that much. I came up with this script which I'm pretty sure it can be written in a better way but this is what I can do. When I stand on the platform, you have 1 second before it starts moving. However, instead of slowly moving into the position I've set it to, it teleports there. How can I make it so the platform moves slowly to where I set it up to instead of teleporting?

function Touched(hit)
    if hit then
      for i = 1,50 do
    wait(1)
    script.Parent.CFrame = CFrame.new(19.5, 0.5, 219.5)
    wait (5)
end
    end
end

script.Parent.Touched:Connect(Touched)
0
I know this isn't realated but you can use body position to make the brick smoothly go to the new position (if the brick isn't anchored) Nguyenlegiahung 1091 — 4y
0
cant you use tween service p0vd 207 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Your script won't work because you not really increase the block.CFrame value slowly:

for i = 1,50 do
    wait(1)
    script.Parent.CFrame = CFrame.new(19.5, 0.5, 219.5) -- the CFrame instantly increase
    wait(5)
end

The solution is use Tween:

Tweens are used to interpolate the properties of instances. These can be used to create animations for various Roblox objects.

For example:

function touch(hit)
    local goal = {}
    goal.CFrame = CFrame.new(19.5, 0.5, 219.5) -- the final goal to the tween complete

    local tweenInfo = TweenInfo.new(5) -- the time tween need to complete

    local tween = TweenService:Create(script.Parent, tweenInfo, goal) -- create tween

    tween:Play() -- don forget to play it
end

script.Parent.Touched:Connect(Touched)

Hope it helping you :D

Ad

Answer this question