Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Using CFrame, moving a block slowly to a position?

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)

2 comments

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)

0

cant you use tween service

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.