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

Body Position positioning me to somewhere random?

Asked by 3 years ago
Edited 3 years ago

I do not know the issue. But whenever the BP is used it just positions me to somewhere random? Its supposed to be a jump, and holds the player in air while a projectile fires. (A jump kind of effect into the air) I don't know the problem, but I have attached my script to this thread. Please help!

-- Variables
local UIS = game:GetService("UserInputService")
local Cam = script:WaitForChild("CamShake")
local ButtonEvent = script:WaitForChild("BtnDown")
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Debounce = true
local BtnDown = false
Player = game.Players.LocalPlayer
Char = Player.Character

--- Functions:
local Tool = script.Parent

Tool.Equipped:Connect(function()
    Tool.Equip.Value = true
end)

Tool.Unequipped:Connect(function()
    Tool.Equip.Value = false
end)

--- Keybind
UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Z and Debounce == true then
        Debounce = false --and Tool.Equip.Value == true and Tool.Active.Value == "None" then
        BtnDown = true
        --Tool.Active.Value = "WindSlam"

        local Charge = 0
        script.Function:FireServer(Mouse.Hit.p)

        local BG = Instance.new("BodyGyro")
        BG.Parent = Char.HumanoidRootPart
        BG.MaxTorque = Vector3.new(250000,250000,250000)
        BG.CFrame = CFrame.new(Char.HumanoidRootPart.Position, Mouse.Hit.p)
        BG.P = 25000
        BG.D = 140

        local BP = Instance.new("BodyPosition")
        BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        BP.P = 15000
        BP.D = 1250
        BP.Position = Char.HumanoidRootPart.Position
        BP.Parent = Char.HumanoidRootPart

        while BtnDown == true and Charge < 40 do
            BG.CFrame = CFrame.new(Char.HumanoidRootPart.Position, Mouse.Hit.p)
            Charge = Charge + 1
            wait()
        end
        BG:Destroy()
        BP:Destroy()
        ButtonEvent:FireServer()
    end
end)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Z and Tool.Equip.Value == true and Tool.Active.Value == "None" then
        BtnDown = false
        Tool.Active.Value = "WindSlam"
        wait(1.5)

        Tool.Active.Value = "None"

        wait(3)
        Debounce = true
    end
end)

-- Camera Shake

function cameraShake()
    local Character = Player.Character
    local Humanoid = Character:WaitForChild("Humanoid")

    for i = 1, 40 do
        local a = math.random(-100, 100)/100
        local b = math.random(-50, 50)/100
        local c = math.random(-100, 100)/100

        Humanoid.CameraOffset = Vector3.new(a,b,c)
        wait()
    end
    Humanoid.CameraOffset = Vector3.new(0,0,0)  
end

Cam.OnClientEvent:Connect(function()
    cameraShake()
end)
0
do you need to teleport or take a player somewhere? panvvan 20 — 3y
0
I was unable to replicate the issue (I was seizuring in place instead). Could something else be affecting the position of the player? Sparks 534 — 3y

2 answers

Log in to vote
2
Answered by
Sparks 534 Moderation Voter
3 years ago
Edited 3 years ago

I used to use BodyPositions to hold the player in place while firing a move. When I tried your properties, they kind of flung me all over the place. I suggest using a combination of BodyPosition and BodyGyro to help stabilize the player.

local BG = Instance.new("BodyGyro")
BG.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
BG.P = 8500
BG.D = 500
BG.Parent = Char.HumanoidRootPart
BG.CFrame = CFrame.new(Char.HumanoidRootPart.Position, Mouse.Hit.Position)

local BP = Instance.new("BodyPosition")
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.P = 15000
BP.D = 1250
BP.Position = Char.HumanoidRootPart.Position
BP.Parent = Char.HumanoidRootPart

Your issue could be with changing the properties after parenting, which could lead to the BodyPosition's default properties going into play on the physics engine before you set the new ones.

If you have charging or delayed attacks, make sure to update the Gyro's CFrame to the new mouse position every frame.

0
Yeah I do charging. And I have the bodygyro thingy. It's just the BP that keeps messing the move up. XxWingKing 96 — 3y
0
Also, this didn't work. It just didn't do anything XxWingKing 96 — 3y
0
I just tested it and it works. Could something else in your code prevent it from working? Sparks 534 — 3y
0
If you need to force the player to jump then the BP position needs to be Char.HumanoidRootPart.Position + Vector3.new(0, JUMPHEIGHTHERE, 0) Sparks 534 — 3y
View all comments (7 more)
0
Would you want me to edit it and show you? XxWingKing 96 — 3y
0
Yes, it would help a lot if you could show a bit more. Have you checked to see if your code reaches the BodyPosition part? You should check the explorer when Playing Solo to see if the BodyPosition was made at all. Sparks 534 — 3y
0
Did you end up figuring out the problem? You upvoted my answer so I am not sure if that means you fixed it or not. Sparks 534 — 3y
0
The BP is being made. (And the gyro works). I edited the thread please re-read it. XxWingKing 96 — 3y
0
I again tried your code for your first UIS.InputBegan connection and the BodyPosition and BodyGyro work as expected. Sparks 534 — 3y
0
Whats your discord? I'll give you the full server script. XxWingKing 96 — 3y
0
My Discord is Zatara#0001. However, when I tried putting the LocalScript in a tool, I got an error saying "attempted to index HumanoidRootPart with nil." Did you get this error as well in the output? Sparks 534 — 3y
Ad
Log in to vote
1
Answered by
panvvan 20
3 years ago
Edited 3 years ago

u didnt rlly explain why u need to use this so i assume you would want to teleport a player somewhere so u can simply make a part where u want to teleport them make it invisible and and can collide of and use this (I EDITED THE ANS)

Char.HumanoidRootPart.CFrame = Char.Head.CFrame + Vector3.New(0, 5, 0)

this should teleport the player slightly above their head then u can anchor the player or whatever u want to keep it in air the unanchoore the player to get it back down

0
It will be appreciated if this solves your problem and dont forget to accept this ans panvvan 20 — 3y
0
Its supposed to be a jump, and holds the player in air while a projectile fires. (A jump kind of effect into the air) XxWingKing 96 — 3y
0
ok so make the humanoid root part go above the head panvvan 20 — 3y

Answer this question