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

How to make an player rise into the air after touching an object?

I am trying to make a wind gust in my game that launches you up into the air. Any idea on how to do it?

Here is my script currently:


		    function partTouched(obj)
		    if obj.Parent:findFirstChild("Humanoid") then
		        script.Parent:findFirstChild("Humanoid").Position = 	script.Parent:findFirstChild("Humanoid").Position + Vector3.new(0,1,0)
		        end
		end
		 
		script.Parent.Touched:connect(partTouched)

when i test this it comes up with this error

Workspace.IceFX.Script:3: attempt to index nil with 'Position'

1 answer

✓ Accepted answer

The Humanoid doesn't have a Position property, so you should try using the HumanoidRootPart to move the player. Also, if you only want players to touch it and be launched into the air, consider using

function partTouched(obj)
    local player = game.Players:GetPlayerFromCharacter(obj.Parent)
    if player then
        obj.Parent.HumanoidRootPart.Position += Vector3.new(0, 1, 0)
    end
end

script.Parent.Touched:Connect(partTouched)

However, if you're looking to launch (fling) the player into the air instead of teleporting, use the AssemblyLinearVelocity:

function partTouched(obj)
    local player = game.Players:GetPlayerFromCharacter(obj.Parent)
    if player then
        obj.Parent.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 50, 0)
    end
end

script.Parent.Touched:Connect(partTouched)

2 comments

0

the second one is not working it is instead doing a glitched jump when jump is pressed.

0

Try using a body velocity instead with max force and destroy it a few seconds after

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