Lifting part. When entered lifts, when exited stops

How would I go about making a part that when a player is in, elevates them until they leave the part.

So basically an elevator but all in just 1 block. Another example would be like the Minecraft water, but without having to move upwards.

Iv’e been searching and can’t find anything for this. Anyone have any ideas?

Here is a basic script I wrote which could help you a bit:

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local Part = script.Parent

local OriginalCFrame = Part.CFrame
local GoalCFrame = CFrame.new(OriginalCFrame.Position + Vector3.new(0, 10, 0))

local CharactersStanding = {}
local LiftTween = TweenService:Create(Part, TweenInfo.new(1), {CFrame = GoalCFrame})
local LowerTween = TweenService:Create(Part, TweenInfo.new(1), {CFrame = OriginalCFrame})

function ValidateTouchedEvent(otherPart)
	local character = otherPart.Parent
	if not character or not character:IsA("Model") then return end
	
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end
	
	return character
end

Part.Touched:Connect(function(otherPart)
	local character = ValidateTouchedEvent(otherPart) print(character)
	if not character then return end
	
	table.insert(CharactersStanding, character)
end)

Part.TouchEnded:Connect(function(otherPart)
	local character = ValidateTouchedEvent(otherPart) print(character)
	if not character then return end
	
	local characterIndex = table.find(CharactersStanding, character)
	if not characterIndex then return end
	
	table.remove(CharactersStanding, characterIndex)
end)

RunService.Heartbeat:Connect(function(deltaTime)
	if #CharactersStanding <= 0 then
		if LowerTween.PlaybackState ~= Enum.PlaybackState.Playing then
			LowerTween:Play()
		end
		LiftTween:Pause()
	else
		if LiftTween.PlaybackState ~= Enum.PlaybackState.Playing then
			LiftTween:Play()
		end
		LowerTween:Pause()
	end
end)

The table CharactersStanding collects characters (also non-player ones) that are currently standing on the part, it does so so the tween won’t cancel itself when it detects any character jumping of (for example) while other player is still standing there. I hope this helps, BTW there’s a lot of things you should change here (for example, change the tween info time depending on the desired speed of the platform and where it is located in relation to the goal cframe, you know t = d / v)

He actually is looking for a Part that when the player walks inside of it acts like water and floats them up.
@SyntaxChase you should add a VectorForce to the player and then destroy the force after the player is lifted out.

Well couldn’t I just make the gravity low and jump the player and then when they leave it gets set back to normal.

An example would be like this.

1 Like

Gravity would be fine, but the only thing is that affects the entire game. If you have other players they’d experience the gravity change as well wherever they were on the map.

What about linear velocity? Would this work?

I’ve used a BodyPosition for this type of movement before in a ‘teleport tube’ kind of elevator before. It basically pushes the player to whatever position.
It’s been deprecated though, so maybe use the newer AlignPosition instead.

What do you use it in a LocalScript? Would it still affect the entire Game?

@SyntaxChase
This is in a server Script.
Of course you’ll have to change the b.Position and the task.wait time, but everything should work for you.

function onTouched(hit)
    local character = hit.Parent
	if character and character:findFirstChild("Humanoid") then
		local a = Instance.new("Attachment")
		a.Parent = character.HumanoidRootPart
		
		local b = Instance.new("AlignPosition")
		b.ApplyAtCenterOfMass = true
		b.Position = Vector3.new(82.909, -444.249, 342.936)
		b.Mode = 0
		b.Attachment0 = a
		b.Responsiveness = 20
		b.MaxForce = 20000
		b.Responsiveness = 20
		b.MaxVelocity = 100
		b.Parent = character.Torso
		
		local g = Instance.new("BodyGyro")
		g.Parent = character.Torso
		
		task.wait(3.5)
		a:Destroy()
        b:Destroy()
		g:Destroy()
    end
end
script.Parent.Touched:connect(onTouched)
1 Like

Thanks, but I think you replied to the wrong person, I asked how to change the Gravity for the LocalPlayer

Oh jeez, sorry 'bout that. I just @'d Colourful in the previous post.

I don’t know if you can change local gravity since it’s a Workspace item, not a local item. I think if you wanted to change just one player’s gravity you’d have to insert a force inside them.

Oh okay, I’ll try it when I get home and (if I remember) update her in the post