Can someone help me understand why this isn't working? Big juicy monkey brain no work right
This question has been solved by the original poster.
I have a character ability system that works for the most part, however, for some reason I can't get my head around, this won't work. The RemoteEvent I have set up is only supposed to execute once, and then check that the ability that it's linked to is disabled, yet after the first time it completely breaks, especially if you spam it. Obviously hints towards something not being reset properly, but it is? Idk but here's the code:
005 | local player = game:GetService( "Players" ):WaitForChild(script.Parent.Name) |
006 | local character = workspace:WaitForChild(player.Name) |
007 | local humanoid = character:WaitForChild( "Humanoid" ) |
009 | local RunService = game:GetService( "RunService" ) |
010 | local ServerStorage = game:GetService( "ServerStorage" ) |
012 | local Events = game:GetService( "ReplicatedStorage" ).RemoteEventsAndFunctions |
014 | local SetHUDProgressBar = Events.SetHUDProgressBar |
016 | local AbilityEvents = Events.Abilities |
018 | local disableActions = script.DisableActions |
020 | local ability 1 = script.Ability 1 |
021 | local ability 2 = script.Ability 2 |
022 | local ability 3 = script.Ability 3 |
023 | local abilitySlots = { ability 1 , ability 2 , ability 3 } |
025 | local activateAbility 1 Cooldown = false |
026 | local activateAbility 2 Cooldown = false |
027 | local activateAbility 3 Cooldown = false |
028 | local ability 1 Cooldown = 0 |
029 | local ability 2 Cooldown = 0 |
030 | local ability 3 Cooldown = 0 |
031 | local ability 1 Disabled = false |
032 | local ability 2 Disabled = false |
033 | local ability 3 Disabled = false |
039 | local SlamEvent = AbilityEvents.Slam |
040 | local ChargeEvent = AbilityEvents.Charge |
041 | local PunchEvent = AbilityEvents.Punch |
043 | local slamFolder = script.BruteMoveset.Slam |
044 | local slamAttackTime = slamFolder.AttackTime.Value |
045 | local slamRecoveryTime = slamFolder.RecoveryTime.Value |
047 | local slamAnim = slamFolder.Animations.Slam |
048 | local slamRecovery = slamFolder.Animations.SlamRecovery |
049 | local slamAnimTrack = humanoid:LoadAnimation(slamAnim) |
050 | local slamAnimRecoveryTrack = humanoid:LoadAnimation(slamRecovery) |
056 | local function GetAbilitySlot(abilityFolder) |
057 | for i, v in ipairs (abilitySlots) do |
058 | if v.Value = = abilityFolder then |
066 | local function ActivateCooldown(slotIndex) |
067 | if slotIndex = = 0 then |
068 | ability 1 Cooldown = abilitySlots [ 0 ] .Value.Cooldown.Value |
069 | activateAbility 1 Cooldown = true |
070 | elseif slotIndex = = 1 then |
071 | ability 2 Cooldown = abilitySlots [ 1 ] .Value.Cooldown.Value |
072 | activateAbility 2 Cooldown = true |
073 | elseif slotIndex = = 2 then |
074 | ability 3 Cooldown = abilitySlots [ 2 ] .Value.Cooldown.Value |
075 | activateAbility 3 Cooldown = true |
079 | local function GetAbilityDisabled(slotIndex) |
080 | if slotIndex = = 0 then |
081 | return ability 1 Disabled |
082 | elseif slotIndex = = 1 then |
083 | return ability 2 Disabled |
084 | elseif slotIndex = = 2 then |
085 | return ability 3 Disabled |
089 | local function SetAbilityDisabled(slotIndex, value) |
090 | if slotIndex = = 0 then |
091 | ability 1 Disabled = value |
092 | elseif slotIndex = = 1 then |
093 | ability 2 Disabled = value |
094 | elseif slotIndex = = 2 then |
095 | ability 3 Disabled = value |
099 | local function SpawnAOE(size, cframe) |
100 | local newAOE = ServerStorage.GameplayObjects.DestructiveAOE:Clone() |
101 | newAOE.Instigator.Value = player.Character |
102 | newAOE.Size = Vector 3. new(size, size, size) |
103 | newAOE.Parent = workspace |
104 | newAOE.CFrame = cframe |
105 | newAOE.BreakWelds.Disabled = false |
112 | SlamEvent.OnServerEvent:Connect( function (_player) |
113 | local slotIndex = GetAbilitySlot(slamFolder) |
114 | local abilityDisabled = GetAbilityDisabled(slotIndex) |
116 | if _player = = player and slotIndex ~ = - 1 and abilityDisabled = = false then |
117 | SetAbilityDisabled(slotIndex, true ) |
118 | disableActions.Value = true |
120 | SetHUDProgressBar:FireClient(_player, slotIndex, 1 , false , 0 ) |
123 | slamAnimTrack:AdjustSpeed( 1 /slamAttackTime - ( 1 /slamAttackTime) * 0.2 ) |
125 | slamAnimTrack:GetMarkerReachedSignal( "AboutToSlam" ):Connect( function (stringParam) |
126 | slamAnimTrack:AdjustSpeed( 1 ) |
129 | slamAnimTrack.Stopped:Connect( function () |
130 | SpawnAOE(slamFolder.AOESize.Value, character.HumanoidRootPart.CFrame * CFrame.new( 0 ,- 9 ,- 10 )) |
131 | slamAnimRecoveryTrack:Play() |
132 | slamAnimRecoveryTrack:AdjustSpeed( 1 /slamRecoveryTime) |
134 | slamAnimRecoveryTrack.Stopped:Connect( function () |
135 | disableActions.Value = false |
136 | ActivateCooldown(slotIndex) |
137 | SetHUDProgressBar:FireClient(_player, slotIndex, 0 , true , abilitySlots [ slotIndex ] .Value.Cooldown.Value) |
143 | RunService.Stepped:Connect( function (_time, step) |
144 | if activateAbility 1 Cooldown = = true and ability 1 Disabled = = true then |
145 | ability 1 Cooldown = ability 1 Cooldown - step |
147 | if ability 1 Cooldown < = 0 then |
148 | activateAbility 1 Cooldown = false |
149 | ability 1 Disabled = false |
153 | if activateAbility 2 Cooldown = = true and ability 2 Disabled = = true then |
154 | ability 2 Cooldown = ability 2 Cooldown - step |
156 | if ability 2 Cooldown < = 0 then |
157 | activateAbility 2 Cooldown = false |
158 | ability 2 Disabled = false |
162 | if activateAbility 3 Cooldown = = true and ability 3 Disabled = = true then |
163 | ability 3 Cooldown = ability 3 Cooldown - step |
165 | if ability 3 Cooldown < = 0 then |
166 | activateAbility 3 Cooldown = false |
167 | ability 3 Disabled = false |