Is there a reason you’re storing that, that way. And again I don’t see where you’re reading that value from it after you set it with Depth.Value = (math.floor((HumanoidRootPart.Position.Y / 5) * 10) / 10)
--local script
local player=game:GetService("Players").LocalPlayer
local humanoidRootPart=player.Character:WaitForChild("HumanoidRootPart")
local depth=nil
function getZone()
depth=(math.floor((humanoidRootPart.Position.Y/5)*10)/10)
if depth >= 0 then return "Surface" end
if depth >= -10 then return "Underground" end
if depth >= -60 then return "Traveling" end
if depth >= -120 then return "Bodies" end
if depth >= -200 then return "Deep" end
if depth >= -300 then return "Unknown" end
if depth >= -400 then return "Treacherous Halls" end
if depth >= -500 then return "Uncharted Territory" end
if depth >= -3000 then return "The Void" end
return "Unknown"
end
local zone=getZone()
print(zone)
Working is better than inefficient looking. Also that is tight for what it is doing. I don’t know where you’re using this so it’s a bit of guessing. The function part is all that matters. Server or local Client script … once you lock onto HumanoidRootPart.
local Zones = {
{["Name"] = "Surface"; ["Depth"] = 0};
{["Name"] = "Underground"; ["Depth"] = -10};
{["Name"] = "Traveling"; ["Depth"] = -60};
...
}
function getZone()
Depth = (math.floor((humanoidRootPart.Position.Y / 5) * 10) / 10)
for _, Zone in Zones do
if Depth < Zone.Depth then continue end
return Zone.Name
end
return "Unknown"
end
-- To match the module:
function getZone()
Depth = (math.floor((humanoidRootPart.Position.Y / 5) * 10) / 10)
for ZoneName, ZoneDepth in Zones do
if Depth < ZoneDepth then continue end
return ZoneName
end
return "Unknown"
end
--// Variables
local Player = game.Players.LocalPlayer
local Zones = require(game.ReplicatedStorage:WaitForChild("Zones"))
while wait() do
script.beep:Play()
script.Parent.Value.Text = Player.Depth.Value .. " m"
task.wait(2)
end
Server Script:
--// Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
Players.PlayerAdded:Connect(function(player: Player)
local Depth = Instance.new("NumberValue")
Depth.Parent = player
Depth.Name = "Depth"
RunService.Heartbeat:Connect(function()
if player.Character then
local Root = player.Character:FindFirstChild("HumanoidRootPart")
if Root then
Depth.Value = (math.floor((Root.Position.Y / 5) * 10) / 10)
end
end
end)
end)