RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"the distance is not being tracked properly, can you fix this?"
Certainly! If you're looking to track the distance between the player and a specific object or point in the game and update a text label accordingly, you'll need to continuously check the distance and update the label. Below is an example script that could be placed in a LocalScript to track the distance between the player's character and a specific part (for instance, "MoveToPart") in the game. This script updates a text label with the current distance, fixing the issue of not properly tracking distance. ```lua -- LocalScript under StarterGui or a ScreenGui within the player's PlayerGui local player = game:GetService("Players").LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") -- Make sure this is the correct path to your ScreenGui local textLabel = screenGui:WaitForChild("TextLabel") -- Ensure you have a TextLabel named "TextLabel" local targetPart = game.Workspace:WaitForChild("MoveToPart") -- The part you want to measure distance to -- Function to update the label with the distance local function updateDistance() while true do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local distance = (player.Character.HumanoidRootPart.Position - targetPart.Position).magnitude textLabel.Text = "Distance: " .. math.floor(distance) -- Update the text label with the distance, rounded down end wait(0.1) -- Update every 0.1 seconds. Adjust as needed. end end -- Start tracking updateDistance() ``` This script assumes you have a `ScreenGui` with a `TextLabel` inside the player's `PlayerGui`, and a part named "MoveToPart" in the Workspace. It continuously calculates the distance between the player's `HumanoidRootPart` and the `MoveToPart`, updating the `TextLabel` with the current distance rounded down to the nearest whole number. Remember to adjust the script paths (`"ScreenGui"` and `"TextLabel"`) to match the actual hierarchy and names in your game. Also, ensure the script is running in a context where it has access to the player's `PlayerGui`, typically within a `LocalScript` under `StarterGui` or directly within the `PlayerGui`.