Hello, I want to create a script that gives me the players distance relative of two parts. Start Part and End Part the closer the player is to End Part the closer the decimal the script returns is to 1. And if the player is further away then the Start Part then the code just returns 0. It is determining horizontal distance. Both parts are on the same level. Any help is much appreciated, thankyou
Update: I figured it out and by I, I mean an AI, anyways here is the script i used, its not perfect however it works for me
local Players = game:GetService("Players")
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local startPart = game.Workspace:WaitForChild("Start")
local endPart = game.Workspace:WaitForChild("End")
function update()
while task.wait() do
for i, player in pairs(Players:GetChildren()) do
local hrpPosition = game.Workspace:WaitForChild(player.Name).HumanoidRootPart
local distance = (endPart.Position - hrpPosition.Position).Magnitude
local Gui = player.PlayerGui
local ProgressGui = Gui.ProgressGUI
local Frame = ProgressGui.Frame
Frame:WaitForChild(player.Name.."Image").Position = UDim2.new(math.clamp(1 - (distance / 100),0,1))
end
end
end
task.spawn(update)
game.Players.PlayerAdded:Connect(function(plr)
for i, player in pairs(Players:GetChildren()) do
local plrGui = player.PlayerGui
local image = plrGui:WaitForChild("ImageTemplate"):Clone()
local content = Players:GetUserThumbnailAsync(plr.UserId, thumbType, thumbSize)
image.Name = plr.Name.."Image"
image.Image = content
image.BackgroundTransparency = 1
image.Parent = player.PlayerGui.ProgressGUI.Frame
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.