Value wont change no matter what

I tried several ways to change the value but, it just won’t change, I’m not sure what I’m doing wrong.

ocal RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local CubeShiftEvent = RS:WaitForChild("CubeShiftEvent")
local RunSHift = RS:WaitForChild("BullRUN")
local model = game.ReplicatedStorage.StarterCharacter
local player = game.Players.LocalPlayer
local NVal = false
local otherSpirnt = game.StarterGui:WaitForChild("SprintScript")
local Humanoid = player.Character:WaitForChild("Humanoid")

----------------------------------
local VoidShift = RS:WaitForChild("Void")
local isRunning = false
local triggerKeyAttack = Enum.KeyCode.Z
UIS.InputBegan:Connect(function(input,gameProcessed)
	
	local AbleRunning = false
	local AbleStoped = false
	local triggerKey = Enum.KeyCode.LeftShift
	local REGULAR_SPEED = 16
	local RUN_SPEED = 30
	
	--------------------------------cooldowns
	local SwordSwingCoolDown = 1
	local CanAttack = true
	
	-----------------
	if not gameProcessed then
		
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.E then
					NVal = true
				print("E is pressed Nval is set to",NVal)
				--local newAv = model:Clone()
				--newAv.Parent = game.StarterPlayer
				AbleRunning = true
				wait(.1)
				CubeShiftEvent:FireServer(model)
				--------------------------------------
			
			
				
				
				
			end
		end
	end
	---------------------------------------------------------Attacks
	

	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Z and NVal then
			print("z fired")
			VoidShift:FireServer(CanAttack,SwordSwingCoolDown)
		else
			print("Value is flase")

    end
	
       end
2 Likes

What variable are you trying to change the value of?

1 Like

Nval, trying to make it so that the Z ability wont activate if the character didn’t press E first, the E ability is kinda like a transformation

1 Like

Hi, could you please show us the output of the following script?

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local CubeShiftEvent = RS:WaitForChild("CubeShiftEvent")
local RunSHift = RS:WaitForChild("BullRUN")
local model = game.ReplicatedStorage.StarterCharacter
local player = game.Players.LocalPlayer
local NVal = false
local otherSpirnt = game.StarterGui:WaitForChild("SprintScript")
local Humanoid = player.Character:WaitForChild("Humanoid")

----------------------------------
local VoidShift = RS:WaitForChild("Void")
local isRunning = false
local triggerKeyAttack = Enum.KeyCode.Z
UIS.InputBegan:Connect(function(input,gameProcessed)
	
    print("Starting our connection with NVAL having the value of ", tostring(NVal))

	local AbleRunning = false
	local AbleStoped = false
	local triggerKey = Enum.KeyCode.LeftShift
	local REGULAR_SPEED = 16
	local RUN_SPEED = 30
	
	-- Cooldowns --
	local SwordSwingCoolDown = 1
	local CanAttack = true
	
	-- --
	if not gameProcessed then
		
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.E then
                print("Continuing our connection with NVAL having the value of ", tostring(NVal))

				NVal = true
				print("E is pressed Nval is set to",NVal)

				--local newAv = model:Clone()
				--newAv.Parent = game.StarterPlayer

				AbleRunning = true

				task.wait(.1)
                print("Ending our connection with NVAL having the value of ", tostring(NVal))
				CubeShiftEvent:FireServer(model)			
			end
		end
	end
	-- Attacks --

	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Z and NVal then
			print("z fired")
			VoidShift:FireServer(CanAttack,SwordSwingCoolDown)
		else
			print("Value is flase")

        end
    end
	
end)

Out put just pressing Z is “Value is false” and output after pressing e is the same

I just pasted your script into my studio and it prints e correctly but z wrong. Here’s why
You put both the e and z functions in the same connection of InputBegan
Put the z function in another connection like this

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local CubeShiftEvent = RS:WaitForChild("CubeShiftEvent")
local RunSHift = RS:WaitForChild("BullRUN")
local model = game.ReplicatedStorage.StarterCharacter
local player = game.Players.LocalPlayer
local NVal = false
local otherSpirnt = game.StarterGui:WaitForChild("SprintScript")
local Humanoid = player.Character:WaitForChild("Humanoid")

----------------------------------
local VoidShift = RS:WaitForChild("Void")
local isRunning = false
local triggerKeyAttack = Enum.KeyCode.Z
UIS.InputBegan:Connect(function(input,gameProcessed)

	print("Starting our connection with NVAL having the value of ", tostring(NVal))

	local AbleRunning = false
	local AbleStoped = false
	local triggerKey = Enum.KeyCode.LeftShift
	local REGULAR_SPEED = 16
	local RUN_SPEED = 30

	-- Cooldowns --
	local SwordSwingCoolDown = 1
	local CanAttack = true

	-- --
	if not gameProcessed then

		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.E then
				print("Continuing our connection with NVAL having the value of ", tostring(NVal))

				NVal = true
				print("E is pressed Nval is set to",NVal)

				--local newAv = model:Clone()
				--newAv.Parent = game.StarterPlayer

				AbleRunning = true

				task.wait(.1)
				print("Ending our connection with NVAL having the value of ", tostring(NVal))
				CubeShiftEvent:FireServer(model)			
			end
		end
	end
	-- Attacks --

end)

UIS.InputBegan:Connect(function(input,gameproccessevent)
	if not gameproccessevent then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Z and NVal then
				print('z')
				VoidShift:FireServer(model)
			else
				print('nval is fasle')
			end
		end
	end
end)

It works now if you press z after pressing e

1 Like

The output it’s giving me says it’s still false

it switches to true for a second but then it goes back to being false

That’s strange. Because once I pressed e and pressed Z after, it prints true. Is there anywhere else in your script where you set NVal to false?

no, i don’t have it to set false anywhere else

use a script rather than a local script

it needs to be in a local script

1 Like

it will not work if it is in a local script

you are changing the value for the client only and not for the server you need to do this in a script