#Melee Attack Code not working Properly

75 messages · Page 1 of 1 (latest)

somber ingot
#

Hi, two days ago I found a massive bug that was affecting my code for my fighting game and managed to patch it out yesterday and fix most of my code that was affected. The exception to this was my melee attack code which remained partially bugged. Before the massive bug, the code was supposed to increment through multiple attacks depending on if the player clicked in succession within the set time limit. But now that it's broken, it doesn't cycle through the attacks normally and instead requires the player to repeatedly spam keys in order to cycle through. If anyone could give some suggestions or advice on how to fix this, it would be a massive help because it confuses me how it doesn't work anymore despite using the same logic as before. I've attached the script to this question as a file so anyone can read it.

wise arrow
pulsar condor
wise arrow
somber ingot
#

oh

#

dang

#

uh

#

lemme try something

#

function module.countChange(player)
local Data = game.ReplicatedStorage.PlayerData:FindFirstChild(player.Name)
local count = Data.Values.ATKcount.Value

if not Data.Values.LMB.Value then return end

if Data.Values.ATKcount.Value < maxCount and Data.Values.LMB.Value then
    if isStart then
        isStart = false
        Data.Values.ATKcount.Value = 1
    else
        Data.Values.ATKcount.Value += 1
    end
else
    Data.Values.ATKcount.Value = 1
end

local currentCount = Data.Values.ATKcount.Value

task.delay(AllowedTime, function()
    if currentCount == Data.Values.ATKcount.Value then -- Check if count hasnt changed, currentCount is the count that isnt updated whilst count is constantly updating
        Data.Values.ATKcount.Value = 1  
        isStart = true
    end
end)
#

this is the most important part

#

it activates every time the player clicks while not stunned and while melee attacks are activated since I have it so you can swap between projectiles and melee attacks

pulsar condor
#

Just need a little better formatting so its easier to read

somber ingot
#

yeah definitely, it just hasn't been my priority as of late

pulsar condor
somber ingot
#

Oh ok

pulsar condor
#

Like the sticker I just posted

somber ingot
#

So just add comments to label what does what?

pulsar condor
#

sorry

#

type your message like that, and put your pasted code where "print" is

somber ingot
#

Oh ok

pulsar condor
#
so it appears like this
#
function module.countChange(player)
    local Data = game.ReplicatedStorage.PlayerData:FindFirstChild(player.Name)
    local count =  Data.Values.ATKcount.Value
    
    if not Data.Values.LMB.Value then return end

    if Data.Values.ATKcount.Value < maxCount and Data.Values.LMB.Value then
        if isStart then
            isStart = false
            Data.Values.ATKcount.Value = 1
        else
            Data.Values.ATKcount.Value += 1
        end
    else
        Data.Values.ATKcount.Value = 1
    end

    local currentCount = Data.Values.ATKcount.Value

    task.delay(AllowedTime, function()
        if currentCount == Data.Values.ATKcount.Value then -- Check if count hasnt changed, currentCount is the count that isnt updated whilst count is constantly updating
            Data.Values.ATKcount.Value = 1  
            isStart = true
        end
    end)
somber ingot
#

I'm dumb idk why I struggled to try and do that

pulsar condor
#

Why are you storing player data in ReplicatedStorage? Why put their data on the player it belongs to?

somber ingot
#

Would that be better for efficiency?

#

I just did it because I couldn't think of what else to do to fix a previous problem

pulsar condor
#

Just feels easier, not sure if it'd fix anything

somber ingot
#

ah ok

wise arrow
somber ingot
#

oh wait yeah cus it would be deleted when the player leaves so I wouldn't have to make a whole script dedicated to clearing any values from players who already left

#

yeah I think I'll change that later

pulsar condor
#

Whats isStart? is that unique to each player? Or is this a script attached to each player?

somber ingot
#

it's a local value in the script itself

spring fulcrumBOT
#

studio** You are now Level 4! **studio

somber ingot
#

it just says whether or not it's the first hit of the combo so you always start on the first attack

#

cus if isStart is false then it knows it's allowed to increment now

pulsar condor
#

So the script that controls this, is it one script that manages many players or is it many scripts each attached to a player

somber ingot
#

right now it's one script that manages many players by taking in the player and using their own seperate data to do stuff

#

but if making it seperate per person would make it more efficient then I can change it

pulsar condor
#

So isStart is one variable for many players?

somber ingot
#

it just hasn't given me any problems yet when I tested multiplayer with my friends

somber ingot
pulsar condor
somber ingot
#

it gets set outside the modules at the top of the script

pulsar condor
#

It looks like youre using it when a count needs to change for any one player, but the value isn't unique to that one player, so that may cause issues.

somber ingot
#

ATKcount?

#

because every player has their own ATKcount in their value file

pulsar condor
#

countChange

somber ingot
#

Ohh ok

#

wait do you mean currentCount?

#

because I don't understand what you mean by currentCount being the problem since it takes in the player it needs to change the count for

pulsar condor
#

No I mean isStart

somber ingot
#

Oh ok

#

so I just make isStart a seperate value each player has?

#

that doesn't sound too hard

#

I'll try it

pulsar condor
#

Just make sure it's unique, or multiple players may override the others, causing their combo to reset

somber ingot
#

Ok

#

I’ll change current count to a player exclusive value too

#

Just so that doesn’t cause any problems either

somber ingot
#

it still doesn't work

#

I think it has something to do with my logic in general

#
    local Data = game.ReplicatedStorage.PlayerData:FindFirstChild(player.Name)
    local count =  Data.Values.ATKcount.Value
    
    if not Data.Values.LMB.Value then return end

    if Data.Values.ATKcount.Value < maxCount and Data.Values.LMB.Value then
        if Data.isStart.Value == true then
            Data.isStart.Value = false
            Data.Values.ATKcount.Value = 1
        else
            Data.Values.ATKcount.Value += 1
        end
    else
        Data.Values.ATKcount.Value = 1
    end
    
    Data.currentCount.Value = Data.Values.ATKcount.Value
    

    task.delay(AllowedTime, function()
        if Data.currentCount.Value == Data.Values.ATKcount.Value then -- Check if count hasnt changed, currentCount is the count that isnt updated whilst count is constantly updating
            Data.isStart.Value = true
            Data.Values.ATKcount.Value = 1  
        end
    end)
pulsar condor
#

Are you using the player's data to determine whether they're pressing the mouse button?

somber ingot
#

I just used remotes for that

#

Like a remote to signal when the input starts and when it ends

#

And it works normally so I don’t see how it could be affecting anything

pulsar condor
#

I'd say add print statements to your if statement where you increase counts. See if youre ever increasing the count, if you are but it's being reset, etc

wise arrow
#

@somber ingot

pulsar condor
somber ingot