What do you want to achieve?
I’m making a combat system, and I just made a stun system, I’m trying to not allow the player to attack if he’s stunned
What is the issue?
If I check if the player isnt idle and return it works fine, but if I add if player isnt idle and they’re stunned it causes the attack event to fire multiple times when it shouldn’t
server script
attackevent.OnServerEvent:Connect(function(player, attacklist, localstate)
local character = player.Character
local torso = character.HumanoidRootPart
local playerstate = character:GetAttribute("State")
if playerstate ~= "Idle" and character:GetAttribute("Stun") == true then return end
for i,v in attacklist do
local opponent = v
local opponentstate = opponent:GetAttribute("State")
local opponenttorso = opponent.HumanoidRootPart
if opponentstate == "Evade" then continue end
if opponent.Name ~= "Rig" then
if player.Team == players:GetPlayerFromCharacter(opponent).Team then print("same team") continue end
if (opponenttorso.Position - torso.Position).Magnitude <= 12 then
opponent.Humanoid:TakeDamage(10)
end
else
opponent.Humanoid:TakeDamage(10)
end
end
character:SetAttribute("State", "Attack")
task.wait(.5)
character:SetAttribute("State", "Idle")
end)
it works if I check on a seperate line but not on the same, not sure why
I made the stun not a player state so it could be easier, because I also have a stuntimer attribute, and checking whenever player state is stun instead of having it separate is easier. Also that doesn’t answer my question?
well, I don’t really have to rewrite it, as I said it works if I check on a separate line. The question I asked was why it doesn’t work if I check on the same, the state is idle and stun is false both times. Also the API doesn’t have an example like I was trying to do.
Also, @NarutoUzmakiAkatsuki can you provide the script containing :FireServer? I think the issue might be occuring because you send attack queries too often and the return conditional can pass more often if character:GetAttribute("Stun") == true is false.
I’m checking for the player state because attributes don’t replicate from the client and I’m changing it in the server, if I don’t check then the player could attack again or they should not be able too. Handling the player states on the client isn’t a good idea. Also the player can exploit and change their client which I’d like to check for.
yes, stun attribute exists. I think I found out, that when doing an if statement with strings is a little bit different that using it with bools, which I think is the issue
I was just confused on why it would do damage when it shouldn’t, not what I was trying to do. I have seen people use “and” for checking if a player can’t do something, but I think those were bool values and not strings
but those are literally copy linked images from the 3 images I posted in this topic.
I know about using or, I just said I was confused about why it wasn’t printing using ~=
also the reason I didn’t use “or” in the original topic post was because if I remember correctly or doesn’t take more than two arguments, and for combat systems I have seen scripts do long checks using and. Which is why I was confused