How to move a a ball part?

I am trying to make a script made to move a sphere part.

Each time the part AssemblyLinearVelocity change the player character die.

Here is my script:

local ball: Part = workspace.ball
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local controlEvent = ReplicatedStorage.controlEvent

function moveBall(velocity: Vector3)
	ball.AssemblyLinearVelocity = velocity
end

controlEvent.OnServerEvent:Connect(function(_p, velocity) moveBall(velocity) end)

I don’t know what could kill the character as the ball is not over the player.

I tried changing the velocity by using the ApplyImpulse method instead of manually changing the AssemblyLinearVelocity however it killed my character.

Hello, The issue might be related to the AssemblyLinearVelocity or ApplyImpulse causing an unexpected reaction on the ball that could result in the ball colliding with the player character, even if it’s not obviously visible.

Another possible cause could be the Roblox physics engine not handling the abrupt velocity changes well, and causing the ball to briefly overlap with the player’s hitbox, which in turn could cause the player’s character to die.

To avoid this, you could try adding a check to ensure that the ball is not near any players before changing its velocity.

function moveBall(velocity: Vector3)
    -- Check if there are any characters near the ball
    local charactersNearBall = workspace:FindPartsInRegion3(
        Region3.new(
            ball.Position - Vector3.new(5, 5, 5),
            ball.Position + Vector3.new(5, 5, 5)
        ),
        nil,
        math.huge
    )
    for _, part in ipairs(charactersNearBall) do
        if part.Parent:FindFirstChild("Humanoid") then
            -- There's a character near the ball, don't change the velocity
            return
        end
    end

    -- There are no characters near the ball, it's safe to change the velocity
    ball.AssemblyLinearVelocity = velocity
end

In this script, FindPartsInRegion3 is used to check for any parts within a 5 stud radius of the ball. If any of these parts belong to a character (determined by checking if the part’s parent has a “Humanoid” child), the function returns without changing the ball’s velocity. Only if there are no characters near the ball does it proceed to change the ball’s velocity.