Blocking system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a blocking system where I hold F with my sword to block.
  2. What is the issue? Include screenshots / videos if possible!
    Other people can make me unblock. Fixed the thing where clicking made me unblock.
    local script
k = ""
bd = false
uis.InputBegan:Connect(function(input,typing)
	if typing == true then return end
	if input.KeyCode == Enum.KeyCode.F then
		bd = true
		k = 'F'
		game.ReplicatedStorage.Sword:FireServer('Blocking')
		while bd == true do
			wait()
		end
		game.ReplicatedStorage.Sword:FireServer('Release')
	end
end)
uis.InputEnded:Connect(function(input,typing)
	if typing == true then return end
	if input.KeyCode == Enum.KeyCode.F and k == 'F' then
		bd = false
	end
end)

script

bd = false
game.ReplicatedStorage.Sword.OnServerEvent:Connect(function(plr,act)
	
	local enabled = true
	local c = plr.Character
	if act == 'Release' then
		bd = false
	end
lseif act == 'Blocking' and c:FindFirstChild('Sword') ~= nil and enabled == true and c:FindFirstChild('Stunned') == nil then
		enabled = false
		bd = true
		local b = Instance.new("BoolValue",c)
		b.Name = 'PerfectBlocking'
		local anim = Instance.new("Animation")
		anim.AnimationId = 'rbxassetid://5837760327'
		local aaa = c.Humanoid:LoadAnimation(anim)
		aaa:Play()
		c.Humanoid.JumpPower = 0
		c.Humanoid.WalkSpeed = 2.5
		spawn(function()
			wait(.2)
			b.Name = 'Blocking'
			wait(.8)
			enabled = true
		end)
		while bd == true do
			wait()
		end
		game.Debris:AddItem(b,0)
		c.Humanoid.JumpPower = 50
		c.Humanoid.WalkSpeed = 16
		aaa:Stop()
end)

I’d really appreciate it if anybody could help me, thanks.

6 Likes

you can use Humanoid.HealthChanged function

1 Like

I wouldn’t really need that. What I want is for me to be able to hold the F key down to block and when I release it I stop blocking. But if I put the bd variable inside the function I can stop blocking by clicking. If it is outside other people can stop me from blocking since it isn’t in the function.

like if u clicking the block stop?

yeah, i probably should edit the post to asking that i’m just really tired

Pretty sure I fixed it. Had nothing to do with the code I sent…

Im just going to rescript the entire thing. Now the whole thing is messed up…

3 Likes
lseif act == 'Blocking' and c:FindFirstChild('Sword') ~= nil and enabled == true and c:FindFirstChild('Stunned') == nil then

line 9, script for remote
“lseif” you should probably (definitely) change that to elseif. thats probably the reason it isnt working

im assuming its “elseif” in the script though since everything you are saying makes me feel like you got elseif there and not lseif. but just in case it isn’t, i suggest changing that to elseif, that might be the fix.

Yeah turns out I was doing it wrong but it was 4 AM and I was really tired… I wen’t to bed and remade it and it works now lol

2 Likes