Function won't work

I’m making a block script for my fighting game. It worked yesterday, but after trying it today it all of a sudden doesn’t work. If I’m being honest, I have no idea what’s wrong.

-- variables yayayayayayaya
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local humanoid = player.Character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local uis = game:GetService("UserInputService")
local cas = game:GetService("ContextActionService")
local rs = game:GetService("RunService")

local blockbool = player.PlayerScripts:WaitForChild("blockbool")
local actualshield = player.PlayerScripts:WaitForChild("blockshield")

local blocka = Instance.new("Animation")
blocka.AnimationId ="rbxassetid://7024791352"
blockanim = animator:LoadAnimation(blocka)

-- actual block funny
local function block(inputObject, gpa)
	print ("the function ran")
	if uis:IsKeyDown(Enum.KeyCode.F) == true and blockbool == false then
		print ("the blockbool thing worked")
		blockbool.Value = true
		actualshield.Parent = player.Character
		humanoid.WalkSpeed = 10
		repeat
			rs.Heartbeat:Wait()
			print ("its repeating")
			blockanim:Play()
			uis:IsKeyDown(Enum.KeyCode.F)
		until
			uis:IsKeyDown(Enum.KeyCode.F) == false
	end
	actualshield.Parent = player.PlayerScripts
	print ("it shouldve stopped now")
	blockanim:Stop()
	humanoid.WalkSpeed = 30
	wait(1.5)
	blockbool.Value = false
end

cas:BindAction("block", block, false, Enum.KeyCode.F)

In the output the it prints that the function ran, except it completely ignores the if statement. In fact, the blockbool isn’t being changed in the first place (it starts as false as all bools do), so I don’t know why it won’t fire. Any help is appreciated, including any improvements to the script in the first place :slightly_smiling_face:

Why don’t you use InputBegan and InputEnded?

Do you mean to make a loop to check if the InputBegan is F? If so I thought that this would save a performance a bit since this seemed to work fine. I’ll try to do that and see if it works.

edit: im stupid it doesnt need a loop

From the looks of it, blockbool is a BoolValue instance, meaning that blockbool == false in the condition of the if block will always be false. Try replacing it with blockbool.Value == false.

I realized I forgot to put .Value there lol. Thank you.

1 Like

InputBegan and InputEnded are Events no need to have them in any loop :).