Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.