Hey, I'm facing an issue that I can't fix. I've tried almost everything, but I can't find a solution. Basically, this script displays text when entering a described area, which is from the top-left corner to the bottom-right corner. So, when you enter the area, it shows the text, which is perfectly fine. However, if you move within this area, it still keeps displaying the text when it shouldn't. This is because I'm already inside the area, and there is no point in displaying the text every time I move inside. It should only display if I leave the area and re-enter. I don't know why it keeps displaying it with every step I make.
Lua:
function isInArea(position, fromPos, toPos)
local x = position.x
local y = position.y
local z = position.z
if z ~= fromPos.z and z ~= toPos.z then
return false
end
return x >= fromPos.x and x <= toPos.x and y >= fromPos.y and y <= toPos.y
end
function onPositionChange(player, newPos, oldPos)
local isInAnyArea = false
for i = 1, #areas do
local area = areas[i]
if isInArea(newPos, area.from, area.to) then
if currentArea ~= area.name then
currentArea = area.name
nameLabel:setText(area.name)
nameLabel:unlock()
g_effects.fadeIn(window, 750)
if fadeOutEvent then
removeEvent(fadeOutEvent)
end
fadeOutEvent = scheduleEvent(function()
currentArea = ""
g_effects.fadeOut(window, 750)
if fadeOutEvent then
removeEvent(fadeOutEvent)
end
end, 3000)
isInAnyArea = true
break
else
isInAnyArea = true
break
end
end
end