Need help to make a Moving Part

How can i make a part that moves downwards to a certain place when the placer touches it then disables the script?

I need this help for a 2d sort of roblox game I am making.

Create a Body Velocity make sure the Vector is -UpVector and give the amount of studs you would like it to go… From there create a hit detection event which fires when the part is touched so it can manually destroy the Body Velocity.

could you give me an example please?

You could use TweenService.

An example would be

local TS = game:GetService("TweenService")

TS:Create(Part, TweenInfo.new(1), {Position = Part.Position + Vector3.new(0,-(how many studs you want it to go down),0}):Play()
2 Likes

I comes up with an error when i try this.


it said there theres an expected closing bracket somewhere.

Also, when i added a closing bracket it did not move

This would probably fix that issue.

local TS = game:GetService("TweenService")

TS:Create(Part, TweenInfo.new(1), {Position = Part.Position + Vector3.new(0,-(how many studs you want it to go down),0)}):Play()
1 Like

thanks, but i need to know how to make it so that when the player touches it then the part moves down?

Adding onto @MultipleStuds example:

local TS = game:GetService("TweenService")
local Debounce = false

Part.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		if not Debounce then
			Debounce = true
			local Tween = TS:Create(Part, TweenInfo.new(10), {Position = Part.Position - Vector3.new(0, 10 ,0)}):Play()
			Tween.Completed:Wait()
			Debounce = false
		end
	end
end)

Oh my gosh, thank you. it even has a sort of gliding type of movement (slowing down at the end of the movement) . I would just like to know what the value is that chooses how far down it goes? / what the numbers in the script decide so that when other people see this they will know what the different things mean.

Most documentation can be found here including TweenInfo: TweenService

The smoothness and slowing down at the end of the platform is all caused by the default EasingStyle which is quad.

image

For example the EasingStyle linear is a consistent speed that doesn’t change whereas quint starts slow then speeds up close towards the end of the tween. EasingStyles can also be reversed with the EasingDirection property (By default is out).

And regarding the position the platform goes to is all related to Vector3. I’ll break it down now:

Position = Here we are defining what property of the part we want to tween.
Part.Position Then we are getting the current position of the Part.
- Vector3.new(0, 10 ,0) And lastly we are negating 10 studs from the current position on the Y axis which is the second number in the Vector3 (X, Y, Z).

If you are looking to make this more advanced the additon of orientation/rotation to the tween could be added within the tweens parameters {} can also be added as that uses Vector3. Though the use of CFrame would probably be a better option due to it storing position, orientation and more within it. (Please note tweening models currently takes a little more effort but tutorials can be found here: Introduction to Tweening Models

Within my script I also have a “debounce” which in simple terms stops the .Touched() event from getting fired repeatedly by the character standing on it. If this wasn’t in place the platforms tween would repeatly be reset and attempted to move again, causing it to fail. Though my system isn’t perfect as once the debounce runs out after the inital tween ends the debounce will reset allowing the event to be fired again and moved even lower, through addition a new variable could be added to stop this, but this is just an example so I didn’t provide it.

3 Likes

wow, great explanation. Thanks a bunch!

Np, good luck with your project.

1 Like

Thanks, i can post a photo of it if you want to know what its about / looks like.