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

HumanoidRootPart Velocity not working?

Hi! I'm trying to fling the player of my game once they join, but I don't know what I did wrong. I put this script in a local script and it isn't working.

local player = game.Players.LocalPlayer
local character = player.Character
local left = Vector3.new(-100,0,0)
character.HumanoidRootPart.Velocity = left

2 answers

✓ Accepted answer

Hello, NotOriginal12345!

You need to wait for the character to be created

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait() -- Waits for character to be created
local character = player.Character
local left = Vector3.new(-100,0,0)
character.HumanoidRootPart.Velocity = left

2 comments

1

you can use "char = player.Character or player.CharacterAdded:Wait()" to save a line

1

I know, but I preffer using this way, it makes more sense on my head

I've came across this problem as well. However, there are some minor things you would need to fix first.

First, you would have to wait for the character to load in because when the player joins, the character is most likely not loaded. To fix this, just simply add player.CharacterAdded:Wait() between lines 1 and 2.

Secondly, the character's HumanoidRootPart may not be loaded in when the character loads in. To fix this, simply wait for the HRP by using :WaitForChild().

I think those are the two main things you would need to fix first before attempting to change the velocity of the HRP.

However, when you do change the velocity of the HRP, it does not seem to change. I found a method that allows the change to happen, however I am not sure why it works. But basically, we change the velocity of the HRP twice with a small wait before each change.

local RunService = game:GetService("RunService")

for i = 1,2 do
	RunService.Heartbeat:Wait()
	-- Change HRP velocity
end

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