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?
01 | function 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 ) |
07 | end |
08 | end |
09 | end |
10 |
11 | script.Parent.Touched:Connect(Touched) |
Your script won't work because you not really increase the block.CFrame value slowly:
1 | for 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 ) |
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:
01 | function 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 |
10 | end |
11 |
12 | script.Parent.Touched:Connect(Touched) |
Hope it helping you :D