Local Script ignoring Bool Value

I am currently trying to make a basic combat system for my game that includes punching and blocking. However whenever you block you can still attack even though I stated for it to do otherwise.

Below is part of the punch script (Local Script, I know its not pretty as I’m still kind of new)


local Blocking = Player.Character.Humanoid:WaitForChild("isBlocking")
local Stunned = Player.Character.Humanoid:WaitForChild("isStunned")

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if attacking == true then return end
		if Blocking == true then return end
		if Stunned == true then return end
		if DHcooldown == false then
			local damage = 10
			stunning = false
			DHcooldown = true
			attacking = true
			DHAnim:Play()
			Remote:FireServer(damage)
			doubpunch:FireServer()
			wait(0.5)
            attacking = false
			DHcooldown = false
		end
	end
end)

The Blocking bool value is defined in the script, and is placed within the Humanoid of a player. The value itself does change both client and server wise when toggled on and off.

The only problem is when you block (the value turns true) and you push the combat key (mouse 1) it checks to see if its true or not which it isn’t, but still throws the punch anyways even though the value is true.

I have also tried adding “.Value” at the end of both but it still does not help.

(Yes I am aware you shouldn’t handle damage values within a local script lol)

It seems you don’t index the bool values

if Stunned.Value == true then return end

You said you tried adding .Value but there is no other way to retrive the value of the bool instance. Without adding .Value your conditional is just comparing instances(boolvalues) and bools

1 Like

This is the best I could do, but I’m pretty sure it still won’t fix your problem. It looks like your code is cutting off some stuff so I don’t know what variables like stunning are.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Blocking = humanoid:WaitForChild("isBlocking")
local Stunned = humanoid:WaitForChild("isStunned")

local damage = 10

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if attacking then return end -- I'm assuming this is not a BooleanValue instance
		if Blocking.Value then return end
		if Stunned.Value then return end
		if not DHcooldown then
			DHcooldown = true
			stunning = false -- I don't know what this is
			attacking = true
			
			DHAnim:Play()
			Remote:FireServer(damage)
			doubpunch:FireServer()
			task.wait(0.5)
         		
			attacking = false
			DHcooldown = false
		end
	end
end)
1 Like

This seemed to have fixed the issue after tweaking it a little bit. It must be because of not adding .Value and probably mixing up the values of the other instances. However is task.wait superior to wait? I’ve never heard of it before.

Yeah I wasn’t too sure personally. But thank you for letting me know!