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

Why does this script only return nearfire = true for one fireplace?

Asked by 8 years ago

I need help knowing why the nearfire bool only goes true when i'm near one of the determined values by the distance.

local function ERROR(text)
    warn("ERROR: ",text)
end

while true do
    wait(1)
    for index, player in pairs(game:GetService("Players"):GetChildren()) do
        local character = player.Character
        if character == nil then
            ERROR("no character for user ", player.Name)
        else
            local torso = character:FindFirstChild("Torso")
            if not torso then
                ERROR("no torso in character for user ", player.Name)
            else
                local torsoposition = torso.Position
                for index, instance in pairs(workspace:GetChildren()) do
                    if string.lower(instance.Name) == "fireplace" then
                        local distance = (instance.Position - torsoposition).magnitude
                        if distance <= 10 or distance <= 10 then
                            player.nearfire.Value = true
                        else
                            player.nearfire.Value = false
                        end
                        print(distance)
                    end
                end
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by 8 years ago

I got the answer I erased the else player.nearfire.Value = false and put player.nearfire.Value = false behind the for loop

Ad

Answer this question