Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I compare three values?

Asked by 3 years ago

Is there a way to make my script more efficient by comparing the three values more directly or is this the best it can be? Here is my script:

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local fire = workspace.Heat
local warmDist = 24
local hotDist = 12
local burnDist = 4

while true do
    wait(1)
    local distance = (char.HumanoidRootPart.Position - fire.Position).magnitude
    if distance <= warmDist then
        print("It's warm")
    end
    if distance <= hotDist then
        print("It's hot")
    end
    if distance <= burnDist then
        print("It's BURNING HOT")
    end
end

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago

This is a good script but I'd use If-Else loops for the if statements incase for values being unknown or nil or not stated. But it depends on your script.

Ad

Answer this question