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.
#Melee Attack Code not working Properly
75 messages · Page 1 of 1 (latest)
is forbidden file only can picture or just copy
no picture.
wat no picture allowed
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
Just need a little better formatting so its easier to read
yeah definitely, it just hasn't been my priority as of late
No I mean like on that message, format what you pasted so the script is easier to read here
Oh ok
Like the sticker I just posted
So just add comments to label what does what?
Oh ok
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)
I'm dumb idk why I struggled to try and do that
Why are you storing player data in ReplicatedStorage? Why put their data on the player it belongs to?
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
Just feels easier, not sure if it'd fix anything
ah ok
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
Whats isStart? is that unique to each player? Or is this a script attached to each player?
it's a local value in the script itself
** You are now Level 4! **
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
So the script that controls this, is it one script that manages many players or is it many scripts each attached to a player
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
So isStart is one variable for many players?
it just hasn't given me any problems yet when I tested multiplayer with my friends
is setting it as a local value in the script the same or does that make it use the same one for everyone?
it depends on where the variable is set
it gets set outside the modules at the top of the script
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.
countChange
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
No I mean isStart
Oh ok
so I just make isStart a seperate value each player has?
that doesn't sound too hard
I'll try it
Just make sure it's unique, or multiple players may override the others, causing their combo to reset
Ok
I’ll change current count to a player exclusive value too
Just so that doesn’t cause any problems either
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)
Are you using the player's data to determine whether they're pressing the mouse button?
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
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
read more about Lua https://youtu.be/LpSe6zut3ME?si=h_tvXFcmEzdgnQ6j
In this video, I show you the very basics of coding in Roblox Studio, with variables, properties, and functions. Hope you Enjoy!
▻Comment any questions down below!
▻Make sure to leave a like 👍
▻Subscribe!
https://www.youtube.com/channel/UCxH4DBOEzsrpvEL1yE30lcw/
▻Join my Discord!
https://discord.gg/cb6jncQ8sr
Check out some more Roblox Co...
@somber ingot
This is so incredibly unhelpful.
This isn't about knowing or not knowing Lua, it's about the logic of the code not functioning as intended.
Please stop posting this video as if it's going to solve every issue anyone has.
I know how to script man, I just needed help with figuring out my logic