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 5 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?

01function Touched(hit)
02    if hit then
03      for i = 1,50 do
04    wait(1)
05    script.Parent.CFrame = CFrame.new(19.5, 0.5, 219.5)
06    wait (5)
07end
08    end
09end
10 
11script.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 — 5y
0
cant you use tween service p0vd 207 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

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

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:

01function touch(hit)
02    local goal = {}
03    goal.CFrame = CFrame.new(19.5, 0.5, 219.5) -- the final goal to the tween complete
04 
05    local tweenInfo = TweenInfo.new(5) -- the time tween need to complete
06 
07    local tween = TweenService:Create(script.Parent, tweenInfo, goal) -- create tween
08 
09    tween:Play() -- don forget to play it
10end
11 
12script.Parent.Touched:Connect(Touched)

Hope it helping you :D

Ad

Answer this question