Whenever I press e the first time it works just fine and when I press off. But when I try pressing E again it says The Parent property of BodyVelocity is locked, current parent: NULL, new parent HumanoidRootPart. How do i fix?
local UserInputService = game:GetService("UserInputService")
local newVel = Instance.new('BodyVelocity')
local function Jump(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.E then
local hmp = game.Players.LocalPlayer.Character.HumanoidRootPart
newVel.Velocity = Vector3.new(0,10,0)
newVel.MaxForce = Vector3.new(10000,10000,10000)
newVel.P = game.Players.LocalPlayer:WaitForChild("power").Value
newVel.Parent = hmp
end
end
local function JumpEnded(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.E then
local hmp = game.Players.LocalPlayer.Character.HumanoidRootPart
hmp.BodyVelocity:Destroy()
end
end
UserInputService.InputBegan:Connect(Jump)
UserInputService.InputEnded:Connect(JumpEnded)
game.Players.LocalPlayer:WaitForChild("power").Changed:Connect(function()
newVel.P = game.Players.LocalPlayer.power.Value
end)
1 Like
in the JumpEnded function, you are destroying the BodyVelocity, meaning it no longer exists. Put newVel inside the Jump function so it creates a new one every jump. You could also make a variable that equals nothing and assign a newly created BodyVelocity to it every jump, that is then destroyed when no longer jumping.
local BodyVelocity
function Jump()
BodyVelocity = Instance.new("BodyVelocity")
end
function DoneJump()
BodyVelocity:Destroy()
end
local UserInputService = game:GetService("UserInputService")
local newVel = Instance.new('BodyVelocity')
function Jump(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.E then
local newVel = Instance.new('BodyVelocity')
local hmp = game.Players.LocalPlayer.Character.HumanoidRootPart
newVel.Velocity = Vector3.new(0,10,0)
newVel.MaxForce = Vector3.new(10000,10000,10000)
newVel.P = game.Players.LocalPlayer:WaitForChild("power").Value
newVel.Parent = hmp
end
end
local function JumpEnded(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.E then
local hmp = game.Players.LocalPlayer.Character.HumanoidRootPart
hmp.BodyVelocity:Destroy()
end
end
UserInputService.InputBegan:Connect(Jump)
game.Players.LocalPlayer:WaitForChild("power").Changed:Connect(function()
newVel.P = game.Players.LocalPlayer.power.Value
end)
I have another problem it does change the power when the value increases
make local newVel = Instance.new('BodyVelocity')
into local newVel
. Remove the equals. In the JumpEnded function, just do newVel:Destroy()
wait a second i just realized this is all in a local script