function getPosition(plr)
local success, result = pcall(function()
return plr.Character.HumanoidRootPart.Position
end)
if success == false or not(typeof(result) == Vector3) then
wait(.25)
print(result)
print("Retrying to get position of player root part. pcall returned " .. tostring(success) .. ". Response returned " .. typeof(result) .. ".")
getPosition(plr)
else
print("Successfully got player position.")
return result
end
end
local deathAlt = game:GetService("ServerScriptService").DeathAltitude.Value
game:GetService("Players").PlayerAdded:Connect(function(plr)
spawn(function()
repeat wait() until (plr.Character)
wait(2)
while wait(.5) do
local pos = getPosition(plr)
print(pos)
if pos.Y <= deathAlt then
print("Player " .. plr.Name .. " is below the safe altitude.")
plr.Character.Health = 0
else
print("Player ".. plr.Name .. " is at a safe altitude.")
end
end
end)
end)
Basically, the code above prints out the following:
Retrying to get position of player root part. pcall returned true. Response returned Vector3.
Alright, so my result
, which is the response of the pcall, is a Vector3
value. This means that not(typeof(result) == Vector3)
returns false
. If the success is true, which returns false
on the first condition, then the second condition ALSO returns false
, why is it still running the first code block which attempts to retry when both statements of the ‘or’ condition are false??