rootPart.AssemblyLinearVelocity not changing (Inconsistent)

Hello. I have been using this simple event to simulate an explosion & launch players for the last 5 months of my game’s development. However, an issue arises at seemingly random respawns that lasts for the duration of the Character’s life. This issue is that the Character’s rootpart.AssemlyLinearVelocity does not appear to be accepting the change in velocity being set, resulting in a lack of propulsion.

Take not that this does not occur in Studio, nor does it persist after respawns.

Code:

explodeEV.OnClientEvent:Connect(function(hitPart, hitDistance, blastCenter)
	if player then
	local rootpart = character:WaitForChild("HumanoidRootPart")
	print("fired explode EV, should work.")
	local root = hitPart.Parent:FindFirstChild("HumanoidRootPart")
	print("hit distance is: " ..hitDistance)

	local look = CFrame.new(rootpart.Position, blastCenter)
	local max_vel = 80 --adjust power of rocket jump
	local radius = 15
	local damp = radius^2/max_vel
	local velocity = (max_vel - hitDistance^2/damp)
		print("velocity is: "..velocity)
		if velocity > 0 then
			rootpart.AssemblyLinearVelocity = -look.LookVector * velocity
			print(-look.LookVector * velocity) -- if look vector is equal to 0, could be the reason rocket jump randomly stops working.
		else
			print("velocity not greater than zero")
		end
	end
end)

Output:


Regardless of the output appearing to be normal, the Character is not propelled by explosions for the remainder of its life.

Hey! There’s a bunch of reasons why this might be happening. Here are a few things you can check:

1. AssemblyLinearVelocity Resetting on Respawn:

After respawning, certain properties of the character might get reset, including AssemblyLinearVelocity. You can fix this by ensuring the velocity is re-applied after respawn.

Solution:
Add a listener for the CharacterAdded event to reapply the velocity when the character respawns:

-- Listen for character respawn and reapply explosion velocity
player.CharacterAdded:Connect(function(character)
    local rootpart = character:WaitForChild("HumanoidRootPart")
    local humanoid = character:WaitForChild("Humanoid")
    
    -- Reset AssemblyLinearVelocity to ensure it works after respawn, like ENSURE it yknow
    rootpart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
end)

2. HumanoidRootPart Physics Behavior:

Sometimes, if the HumanoidRootPart is not considered as an active physical body or if it is attached to other parts (like constraints), the velocity change might not be applied. Ensure that no constraints are blocking the physics update.

Solution:
Disable constraints before applying the velocity:

-- Disable constraints before applying the velocity
for _, constraint in pairs(rootpart:GetChildren()) do
    if constraint:IsA("Constraint") then
        constraint.Enabled = false
    end
end

-- Now apply the velocity after disabling constraints
rootpart.AssemblyLinearVelocity = -look.LookVector * velocity

3. AssemblyLinearVelocity Application Issue:

If AssemblyLinearVelocity is being set too soon after respawn, it might not immediately take effect. Try adding a short delay to ensure the character’s physics parts are fully initialized.

Solution:
Add a short wait before applying the velocity:

task.wait(0.1)  -- Small delay to ensure character is fully initialized
rootpart.AssemblyLinearVelocity = -look.LookVector * velocity

4. Check RootPart’s Position and Orientation:

Ensure that the HumanoidRootPart’s position and orientation are correctly being set. Sometimes, the root part might be reset or not updated as expected, which could prevent velocity changes.

Solution:
Log the root part’s position to track any unexpected changes:

print("Before setting velocity, RootPart velocity: " .. tostring(rootpart.AssemblyLinearVelocity))
rootpart.AssemblyLinearVelocity = -look.LookVector * velocity
print("After setting velocity, RootPart velocity: " .. tostring(rootpart.AssemblyLinearVelocity))

5. More Debugging and Monitoring:

Since this issue doesn’t occur in Studio, it might be related to how the game is running in an online environment. Add more detailed debugging to monitor when the velocity is set and if there are any changes to the character’s state after respawn.

Personally, I had issues with collisions in game, but not in studio. I fixed it by simply waiting for everything to load.

Solution:
Add more print statements to track the behavior and ensure the velocity is applied correctly.

Hope this helps! (it prolly wont) :slight_smile:

1 Like

If the respawns are what is causing it. Then I would double check the root part and make sure it is the new characters root part and not the old one that is destroyed. You can add this line to make sure, hope it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.