From 062fb28cc573c571765b2f78c6c58d935ff2f0fa Mon Sep 17 00:00:00 2001 From: UE4SS Date: Sat, 28 Dec 2024 00:17:25 +0100 Subject: [PATCH] fix(SplitScreenMod): Asynchronously accessing variables is not allowed This fixes "attempt to index a nil value (global 'NewController')". --- assets/Mods/SplitScreenMod/Scripts/main.lua | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/assets/Mods/SplitScreenMod/Scripts/main.lua b/assets/Mods/SplitScreenMod/Scripts/main.lua index 01a3a4702..fa9feae09 100644 --- a/assets/Mods/SplitScreenMod/Scripts/main.lua +++ b/assets/Mods/SplitScreenMod/Scripts/main.lua @@ -38,13 +38,14 @@ local function CreatePlayer() print(string.format("GameplayStatics: %s\n", GetGameplayStatics():GetFullName())) ExecuteInGameThread(function() NewController = GetGameplayStatics():CreatePlayer(PlayerControllerTable[1], #PlayerControllerTable, true) + + if NewController:IsValid() then + table.insert(PlayerControllerTable, NewController) + print(string.format("Player %s created.\n", #PlayerControllerTable)) + else + print("Player could not be created.\n") + end end) - if NewController:IsValid() then - table.insert(PlayerControllerTable, NewController) - print(string.format("Player %s created.\n", #PlayerControllerTable)) - else - print("Player could not be created.\n") - end end @@ -92,13 +93,13 @@ function TeleportPlayers() DidTeleport = true end end - end) - if DidTeleport then - print("Players teleport to Player 1.\n") - else - print("No players could be teleported\n") - end + if DidTeleport then + print("Players teleport to Player 1.\n") + else + print("No players could be teleported\n") + end + end) end