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.
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!
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!
(Yes, I know it’s depreciated. Although it is, it works so I’m fine with it.)