Skip to content
The Chat Archive
gpt-4o-2024-05-13· OpenAI WildChat-4.8M (AI2)

So basically i want to make this script lua roblox work properly and add velocity offset…

  1. User

    So basically i want to make this script lua roblox work properly and add velocity offset by 0.197 while true do heartbeat:Wait() if target == true then local character = game.Players[targetplr].Character.HumanoidRootPart local lastPosition = character.Position task.wait() local currentPosition = character.Position local velocity = (currentPosition - lastPosition) * 0 character.AssemblyLinerVelocity = velocity character.Velocity = velocity end end

  2. Assistant

    To make the script work properly and add a velocity offset of 0.197, there are a few key improvements and adjustments you need to consider. Here is a refined version of your script:

    1. The calculation of velocity should correctly determine the movement over a time period.
    2. The velocity offset should be added.
    3. Ensure that targetplr is defined and valid.
    4. Correct the velocity setting to AssemblyLinearVelocity.

    Here is the improved script:

    -- Replace 'heartbeat' with 'RunService.Heartbeat'
    local RunService = game:GetService("RunService")
    
    local target = true  -- Ensure you set this variable as needed in your script
    local targetplr = "Player"  -- Replace "Player" with the target player's name
    
    local lastPosition
    
    RunService.Heartbeat:Connect(function()
        if target then
            local player = game.Players:FindFirstChild(targetplr)
            
            if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
                local character = player.Character.HumanoidRootPart
                
                if lastPosition then
                    local currentPosition = character.Position
                    local velocity = (currentPosition - lastPosition) / RunService.Heartbeat:Wait()  -- Calculating velocity
                    velocity = velocity + Vector3.new(0, 0.197, 0)  -- Adding the offset
                    character.AssemblyLinearVelocity = velocity
                    
                    -- Optional: You might not need the line below if 'AssemblyLinearVelocity' does the job.
                    -- character.Velocity = velocity
                    
                    lastPosition = currentPosition
                else
                    lastPosition = character.Position
                end
            else
                lastPosition = nil
            end
        end
    end)
    

    Explanation:

    1. Run Service: Utilize RunService.Heartbeat for frame updates.
    2. Target Player Validation: Ensure targetplr is a valid player and their character exists.
    3. Velocity Calculation: Correctly calculates the velocity based on position differences and adds the offset (+ Vector3.new(0, 0.197, 0)).
    4. Tracking Position: Keeps track of the character's last position to calculate movement velocity accurately.

    Replace targetplr value with the actual player's name or set it dynamically as per your requirements. This script continuously updates the player's velocity with an added offset, making sure that the movement calculation is done correctly.