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

How to use BodyPosition with players default X and Z?

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

✓ Accepted answer

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

3 comments

0

I literally have the code in the script wrapped around a mouse.Button1Click

0

I edited my answer

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

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