From b1ccaa227ddb067a875cc3c37e17f70547ae761b Mon Sep 17 00:00:00 2001 From: pluviolithic Date: Sat, 16 Dec 2023 10:16:20 -0500 Subject: [PATCH] Handle common error cases --- src/client/UI/Displays.lua | 22 +++++++++++- .../Combat/Enemies/ApplyDamageToPlayers.lua | 11 +++--- .../Combat/Enemies/ApplyEnemyAnimations.lua | 21 ++++++----- .../Combat/Enemies/ApplyPlayerAnimations.lua | 35 +++++++++++-------- src/server/Combat/Enemies/init.lua | 21 ++++++++--- src/shared/State/Reducer/PetData.lua | 3 ++ 6 files changed, 80 insertions(+), 33 deletions(-) diff --git a/src/client/UI/Displays.lua b/src/client/UI/Displays.lua index 2322415..83570d1 100644 --- a/src/client/UI/Displays.lua +++ b/src/client/UI/Displays.lua @@ -1,4 +1,5 @@ local Players = game:GetService "Players" +local RunService = game:GetService "RunService" local StarterGui = game:GetService "StarterGui" local StarterPlayer = game:GetService "StarterPlayer" local ReplicatedStorage = game:GetService "ReplicatedStorage" @@ -92,11 +93,30 @@ end):andThen(function(interfaces) } playerStatePromise:andThen(function() - StarterGui:SetCore("ResetButtonCallback", false) updateDisplays(displays) store.changed:connect(function() updateDisplays(displays) end) + + -- implementation taken from https://devforum.roblox.com/t/resetbuttoncallback-has-not-been-registered-by-the-corescripts/78470/6 + local coreCall + do + local MAX_RETRIES = 8 + + function coreCall(method, ...) + local result = {} + for _ = 1, MAX_RETRIES do + result = { pcall(StarterGui[method], StarterGui, ...) } + if result[1] then + break + end + RunService.Stepped:Wait() + end + return unpack(result) + end + end + + coreCall("SetCore", "ResetButtonCallback", false) end) end) diff --git a/src/server/Combat/Enemies/ApplyDamageToPlayers.lua b/src/server/Combat/Enemies/ApplyDamageToPlayers.lua index c93339d..f2fdf71 100644 --- a/src/server/Combat/Enemies/ApplyDamageToPlayers.lua +++ b/src/server/Combat/Enemies/ApplyDamageToPlayers.lua @@ -5,6 +5,7 @@ local ServerScriptService = game:GetService "ServerScriptService" local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value +local Janitor = require(ReplicatedStorage.Common.lib.Janitor) local store = require(ServerScriptService.Server.State.Store) local actions = require(ServerScriptService.Server.State.Actions) local selectors = require(ReplicatedStorage.Common.State.selectors) @@ -43,8 +44,10 @@ return function(enemy, info, janitor) end end) - janitor:Add(function() - info.DamageActive = nil - damagePlayers = false - end, true) + if Janitor.Is(janitor) then + janitor:Add(function() + info.DamageActive = nil + damagePlayers = false + end, true) + end end diff --git a/src/server/Combat/Enemies/ApplyEnemyAnimations.lua b/src/server/Combat/Enemies/ApplyEnemyAnimations.lua index 4c2897b..f3908aa 100644 --- a/src/server/Combat/Enemies/ApplyEnemyAnimations.lua +++ b/src/server/Combat/Enemies/ApplyEnemyAnimations.lua @@ -1,6 +1,7 @@ local ReplicatedStorage = game:GetService "ReplicatedStorage" local CollectionService = game:GetService "CollectionService" +local Janitor = require(ReplicatedStorage.Common.lib.Janitor) local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils) local random = Random.new() @@ -8,7 +9,7 @@ local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value return function(enemy, info, janitor) - if info.AnimationsActive then + if info.AnimationsActive or not enemy:FindFirstChild "Configuration" then return end info.AnimationsActive = true @@ -22,7 +23,7 @@ return function(enemy, info, janitor) local currentIndex, animationTrack, animation = 0, nil, nil task.spawn(function() - while runAnimations do + while runAnimations and enemy:FindFirstChild "Humanoid" do currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex) animationTrack = enemy.Humanoid:LoadAnimation(animation) animationTrack.Priority = Enum.AnimationPriority.Action @@ -51,11 +52,13 @@ return function(enemy, info, janitor) end end) - janitor:Add(function() - runAnimations = false - info.AnimationsActive = nil - if animationTrack.IsPlaying then - animationTrack:Stop() - end - end, true) + if Janitor.Is(janitor) then + janitor:Add(function() + runAnimations = false + info.AnimationsActive = nil + if animationTrack.IsPlaying then + animationTrack:Stop() + end + end, true) + end end diff --git a/src/server/Combat/Enemies/ApplyPlayerAnimations.lua b/src/server/Combat/Enemies/ApplyPlayerAnimations.lua index da49c59..0f17247 100644 --- a/src/server/Combat/Enemies/ApplyPlayerAnimations.lua +++ b/src/server/Combat/Enemies/ApplyPlayerAnimations.lua @@ -1,6 +1,7 @@ local ReplicatedStorage = game:GetService "ReplicatedStorage" local ServerScriptService = game:GetService "ServerScriptService" +local Janitor = require(ReplicatedStorage.Common.lib.Janitor) local store = require(ServerScriptService.Server.State.Store) local selectors = require(ReplicatedStorage.Common.State.selectors) local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils) @@ -44,7 +45,11 @@ return function(player, janitor) local sounds = player.Character[weapon]:FindFirstChild "Sounds" while not sounds do task.wait() - sounds = player.Character[weapon]:FindFirstChild "Sounds" + local weaponObject = player.Character:FindFirstChild(weapon) + if not weaponObject then + return + end + sounds = weaponObject:FindFirstChild "Sounds" end for _, sound in sounds:GetChildren() do task.spawn(function() @@ -72,17 +77,19 @@ return function(player, janitor) end end) - janitor:Add(function() - runAnimations = false - if loadedIdleAnimation.IsPlaying then - loadedIdleAnimation:Stop() - end - loadedIdleAnimation:Destroy() - if animationTrack.IsPlaying then - task.spawn(function() - animationTrack.Stopped:Wait() - animationTrack:Destroy() - end) - end - end, true) + if Janitor.Is(janitor) then + janitor:Add(function() + runAnimations = false + if loadedIdleAnimation.IsPlaying then + loadedIdleAnimation:Stop() + end + loadedIdleAnimation:Destroy() + if animationTrack.IsPlaying then + task.spawn(function() + animationTrack.Stopped:Wait() + animationTrack:Destroy() + end) + end + end, true) + end end diff --git a/src/server/Combat/Enemies/init.lua b/src/server/Combat/Enemies/init.lua index e2fa22d..a27c648 100644 --- a/src/server/Combat/Enemies/init.lua +++ b/src/server/Combat/Enemies/init.lua @@ -211,7 +211,9 @@ local function handleEnemy(enemy) "disconnect" ) playerJanitor:Add(humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() - playerJanitor:Destroy() + if Janitor.Is(playerJanitor) then + playerJanitor:Destroy() + end end)) playerJanitor:Add(function() local playerIndex = table.find(info.EngagedPlayers, player) @@ -228,14 +230,22 @@ local function handleEnemy(enemy) orientEnemy(rootPart, info.EngagedPlayers[1].Character.HumanoidRootPart.Position) elseif #info.EngagedPlayers == 0 then lastInCombat = os.time() - enemyAnimationJanitor:Cleanup() + if Janitor.Is(enemyAnimationJanitor) then + enemyAnimationJanitor:Cleanup() + end end end, true) local runServiceJanitor = Janitor.new() runServiceJanitor:Add(RunService.Stepped:Connect(function() - local oldPosition = player.Character.Humanoid.RootPart.Position - task.wait(0.05) + humanoid = if player.Character then player.Character:FindFirstChild "Humanoid" else nil + if not humanoid then + runServiceJanitor:Destroy() + return + end + local oldPosition = humanoid.RootPart.Position + task.wait(0.1) + humanoid = if player.Character then player.Character:FindFirstChild "Humanoid" else nil if not Janitor.Is(playerJanitor) and Janitor.Is(runServiceJanitor) then runServiceJanitor:Destroy() return @@ -243,7 +253,8 @@ local function handleEnemy(enemy) return end if - player.Character.Humanoid.RootPart.Position == oldPosition + humanoid + and humanoid.RootPart.Position == oldPosition and player:DistanceFromCharacter(rootPart.Position) <= fightRange + 5 then runServiceJanitor:Destroy() diff --git a/src/shared/State/Reducer/PetData.lua b/src/shared/State/Reducer/PetData.lua index 51090a4..394129a 100644 --- a/src/shared/State/Reducer/PetData.lua +++ b/src/shared/State/Reducer/PetData.lua @@ -78,6 +78,9 @@ return Rodux.createReducer({}, { if petUtils.getPet(petName):FindFirstChild "PermaLock" and not action.force then continue end + if not draft[action.playerName].LockedPets[petName] then + continue + end draft[action.playerName].LockedPets[petName] -= quantity if draft[action.playerName].LockedPets[petName] < 1 then draft[action.playerName].LockedPets[petName] = nil