How to make a part that brings the player up when touched

Hey there, I was trying to make a part that when touched would bring the player up and then hover on top of the part.
I was trying to use ApplyImpulse() because it was really the only thing I had thought to try and not even that worked, here’s what I tried to do when the part was touched:

local Part = script.Parent

Part.Touched:Connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") then
		local Root = h.Parent.Torso
		Root:ApplyImpulse(Vector3.new(0,500000,0))
	end
end)

I’m not too familiar with this, so I’m struggling and nothing else I’ve found on the dev forum has helped. I don’t need a script or anything I just want somebody to tell me a method please.

You should probably use HumanoidRootPart instead of the Torso. If I am correct R15 characters do not have a part named “Torso” in their character.

Could you just tween the HumanoidRootPart’s position upwards and onto the part?

Ah, probably. But my game does use R6, I’ll try and use HumanoidRootPart and see if that works.

I would also try

Root.Position = Vector3.new(x,y,z)

Well yes I could, that wouldn’t look all that great when it comes to physics, yes I should’ve mentioned that I do want it to be physics based and not really an animation, sorry!

That’s absolutely fine, I’m not so good with velocities though

I had done some more research on BodyVelocity, and I have come up with a solution.

local Part = script.Parent -- The part that the player touches

local function a()
	Part.Touched:Connect(function(h) -- Touched Function that fires when the player touches the part.
		if h.Parent:FindFirstChild("Humanoid") then
			local Root = h.Parent.HumanoidRootPart -- Making RootPart a varible to make it more clean
			local bv = Instance.new("BodyVelocity") -- Creating a BodyVelocity
			if not Root:FindFirstChild("BodyVelocity") then -- Making sure there isn't already a bodyvelocity
				bv.Parent = Root -- Parenting it to the RootPart of the player.
				bv.Velocity = Vector3.new(0,10,0) -- Changing the velocity to go upwards faster, although you can really make this anything you want.
			end
		end
	end)
end

a()

local function b()
	Part.TouchEnded:Connect(function(h) -- fires when the player stops touching the part
		if h.Parent:FindFirstChild("Humanoid") then
			local Root = h.Parent.HumanoidRootPart
			if Root:FindFirstChild("BodyVelocity") then 
				Root:FindFirstChild("BodyVelocity"):Destroy() -- Destroys the BodyVelocity if found.
			end
		end
	end)
end

b()

What this code does is when the Player touches the part it creates a BodyVelocity and parents it to the player, and when the player eventually goes up to far and stops touching the part. When this happens it destroys the BodyVelocity and the player falls back down, touching the part again creating another BodyVelocity and repeating the cycle. This is what I wanted to end up with so I’m counting this as the solution, thanks to the people who did try to help me! :grinning:

(Yes, I know it’s depreciated. Although it is, it works so I’m fine with it.)

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.