Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited by JesseSong 3 years ago

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

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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)
0
the second one is not working it is instead doing a glitched jump when jump is pressed. Meerkatsrawesome 1 — 3y
0
Try using a body velocity instead with max force and destroy it a few seconds after Rare_tendo 3000 — 3y
Ad

Answer this question