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

How to use BodyPosition with players default X and Z?

Asked by 6 years ago

Hey,

I'm trying to do the following script: http://wiki.roblox.com/index.php?title=How_To_Use_BodyPosition

I'm setting it to a button click so that when you press your mouse, it jumps into the sky (0, 500, 0), however it puts the player in the middle of the map (obviously because of the 0 values). I'm wondering how I can get the players X and Z values so that it just goes up, rather than centers and then up.

Thanks

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Edit to an answer:

Assuming you are using the code from the onTouched function defined on the the wiki page, you can get the position of the character this way:

local character = hit.Parent
if character and character:findFirstChild("Humanoid") then
    local b = Instance.new("BodyPosition")

    -- Save the X and Z position of the character
    local characterPositionX = character.HumanoidRootPart.Position.X
    local characterPositionZ = character.HumanoidRootPart.Position.Z

    -- Use the X and Z positions to set the position of the BodyPosition
    b.position = Vector3.new(characterPositionX, 500, characterPositionZ)
    b.maxForce = Vector3.new(500000000, 500000000, 500000000)

    -- changed Torso to HumanoidRootPart for compatability with R15
    b.Parent = character.HumanoidRootPart
    wait(3)
    b.Parent = nil
end
0
I literally have the code in the script wrapped around a mouse.Button1Click RetroSpock 10 — 6y
0
I edited my answer WillieTehWierdo200 966 — 6y
0
Ty. This helped fix the centering issue, but the character was still moving around in the air (not your fault, as I thought that this would fix my issue). I managed to get around it by changing the maxForce X and Z to 0 so that I'd only shoot up into the air! Many thanks RetroSpock 10 — 6y
Ad

Answer this question