The best way to prevent player from attack

I want to make fighting game, and here I have a question. If player1 attacked player2 will get stunned(wont be able to attack), how can I do that? Adding IntValue to character, or just values? What’s the best way to do that?

Try using Humanoid.Sit, and maybe use a remote event to add some client side blur.

I’m sure humanoid.Sit is not the best way to do that

Why not try a remote event?

function onStunned(time)
local b = Instance.new("Blur", game.Lighting)
local gui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
local frame = Instance.new ("Frame", gui)
frame.Size = UDim2.new(1,0,1,0)
frame.BackgroundTransperency = 0
frame.BorderSize = 0 -- cant remember if this is correct sorry

wait (time)

for i = 1, 10 do
frame.BackgroundTransperency = i/10
blur.BlurSize = i/20 -- not sure if this is correct either
wait(.01)
end

gui:Destroy()
b:Destroy()

end

Humanoid.Sit is the easiest way to do it as it is incorporated into Roblox and is unlikely to break. If you use Humanoid.Sit and Humanoid.JumpPower, the player will be frozen.

Well this will be completely based on how you set up your combat system. You can always keep track of each individual player stunned value with a boolean

local function Attack()
    if not (Bool.Value) then
        --<Attack
    else
        --<They are stunned
    end;
end;
--
local function OnHit(Plr)
    Plr.Stunned.Value = true; --< Stun the player they hit
end;

Yeah, I know that, but my bad I didn’t explain what result I wan’t. The thing is I don’t wanna player to use attacks anymore, like using values, so he cannot attack anymore and his attack script disables.

I thought about this but is that stable? Won’t other attacks interrupt value? Like two people might be attacking and if the script will be like wait() then player will be stunned or not stunned for wrong time

How about you just put the player that is stunned into a table and prior to hitting check if the player is in the table

local CanHit = {}

if CanHit[plr.Name] then
     print(plr.Name.."can not hit currently")
else
     print(plr.Name.." can hit and is not stunned")
end

Once a player is stunned, they will stay stunned, whether or not they get hit again during that period. I’m assuming you wouldn’t want them to get stunned even more while they’re stunned :confused:
So getting attacked twice won’t affect anything. Let me try explaining a bit better

local function OnAttack(Plr)
    if(isHitPlayer)then
        if(Plr.Stunned) == false then --<So no matter if another player hits the target player when they're stunned, it won't interupt
            Plr.Stunned = true; 
            delay(3,function() Plr.Stunned = false end)--<Apparently delay() and spawn() are *bad*  But after 3 seconds, target player won't be stunned
        end;
    end;
end;

A big problem that could come from this is that, if this is inside a tool, and that tool is destroyed while a player is stunned, Player will stay stunned forever. You can also use a dictionary as the guy stated, but this must be a single script and not per tool.

1 Like

No, it’s not a tool. Actually I figured it out myself, but I wanted to see peoples thoughts :eyes:
If that’s the only way and it’s good, okay so, thanks for your time.