Once the player enters a zone and the ControlsLoop function is called, the playerState never updates, but when the controlsLoop isn't called, the player state updates, unsure why.
SOLVED: Found the issue i wasn't using the CreateThread function is essential for running it asynchronously without blocking the main thread. This allows the script to continue handling events and state changes as expected.
Code:
local debugMode = true
ScriptFunctionality = {
isInZone = false
-- activeRobberyInfo = {}
}
ScriptFunctionality.InitScript = function()
for i = 1, #Config do
local robberyIndex = Config[i]
local zone = BoxZone:Create(robberyIndex.vec3, 2.0, 2.0, {
name = robberyIndex.name,
heading = 0,
debugPoly = debugMode,
})
--- @param playerState boolean
zone:onPlayerInOut(function(playerState)
ScriptFunctionality.isInZone = playerState
if playerState then
ScriptFunctionality.zoneInfo = robberyIndex
print(("(DEBUG) Player is in the zone: %s"):format(robberyIndex.name))
end
ScriptFunctionality.ControlsLoop()
end)
end
end
ScriptFunctionality.ControlsLoop = function()
while ScriptFunctionality.isInZone do
ShowFloatingText(ScriptFunctionality.zoneInfo.vec3, "Hello there!")
if IsControlJustReleased(0, 38) then
print("(DEBUG) E Was pressed, usually used to start the robbery but this is still in development :)")
end
Wait(5)
end
end
Well to be honest i haven't tried much else, but i'll look into it, i just want a definitive answer as to why this is happening.