GUI doesnt disable

basically, i have 2 scripts (1 local and 1 server) and the problem is that when the chooseKey
function is called, and the player sends the remote to the server saying they escaped, the GUI still shows:


the video shows that once the player hits the 2 escape keys, it should just disappear, but instead the GUI stays there

LOCAL SCRIPT:

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local W = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberW")
local wKey = false
local wPressed = false
local A = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberA")
local aKey = false
local aPressed = false
local S = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberS")
local sKey = false
local sPressed = false
local D = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberD")
local dKey = false
local dPressed = false
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Combo = 0
local EscapeCombo = 2
local Sound = workspace["[SCP:CB] Button Click"]
local StartGrabberEscape = game.ReplicatedStorage.StartGrabberEscape.Value
local GrabberCombo = game.ReplicatedStorage.GrabberCombo
local StartGrabber = game.ReplicatedStorage.StartGrabber
local GrabberEscape = game.ReplicatedStorage.GrabberEscape
task.wait(1)
local EscapeDebounce = false
local Kick = Char.Humanoid.Animator:LoadAnimation(script.Kick)
local Camera = workspace.CurrentCamera
local CanPressKeys = true


function chooseKey()
	local ChosenKey = math.random(1,4)

	if ChosenKey == 1 then
		W.Enabled = true

		wKey = true
		aKey = false
		sKey = false
		dKey = false

		--
		wPressed = true
		aPressed = false
		sPressed = false
		dPressed = false

	elseif ChosenKey == 2 then
		wKey = false
		aKey = true
		sKey = false
		dKey = false

		A.Enabled = true
		--
		aPressed = true
		wPressed = false
		sPressed = false
		dPressed = false
	elseif ChosenKey == 3 then
		wKey = false
		aKey = false
		sKey = true
		dKey = false

		S.Enabled = true
		--
		sPressed = true
		wPressed = false
		aPressed = false
		dPressed = false
	elseif ChosenKey == 4 then
		wKey = false
		aKey = false
		sKey = false
		dKey = true

		D.Enabled = true
		--
		dPressed = true
		wPressed = false
		aPressed = false
		sPressed = false
	end
	

end


----------------------------------
StartGrabber.OnClientEvent:Connect(function()
	chooseKey()
	CanPressKeys = true
end)
----------------------------------
UIS.InputBegan:Connect(function(input, gpo)
	if Combo == EscapeCombo  then

		GrabberEscape:FireServer()
		print("Client: Fired to server that the player escaped.")
		CanPressKeys = false
		W.Enabled = false
		A.Enabled = false
		S.Enabled = false
		D.Enabled = false
		Kick:Play()
		Combo = 0

	end
end)
----------------------------------
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.W and wKey and CanPressKeys == true then

		Combo += 1
		Sound:Play()
		GrabberCombo.Value = Combo
	--[[
		Combotween:Play()
		Combotween.Completed:Connect(function()
			ComboUI.TextLabel.Text = "Combo: "..Combo
		end)
		KeyPressed = true
		--Wtween:Play()
		--Wtween2:Play()
		--Wtween.Completed:Wait()
		--]]
		W.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo or Combo < EscapeCombo then
			chooseKey()
		end


	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.A and aKey and CanPressKeys == true  then
		Sound:Play()
		Combo += 1
		GrabberCombo.Value = Combo


		A.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo or Combo < EscapeCombo then
			chooseKey()
		end
	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.S and sKey and CanPressKeys == true  then
		Combo += 1
		Sound:Play()
		GrabberCombo.Value = Combo

		S.Enabled = false

		task.wait(.2)
		if Combo ~= EscapeCombo or Combo < EscapeCombo then
			chooseKey()
		end
	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.D and dKey and CanPressKeys == true  then
		Combo += 1
		GrabberCombo.Value = Combo
		Sound:Play()

		D.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo or Combo < EscapeCombo then
			chooseKey()
		end
	end
end)

SERVER SCRIPT:

local Char = script.Parent
local Humanoid = Char.Humanoid
local Idle = Humanoid.Animator:LoadAnimation(Char.GrabberIdle)
local Ready = Humanoid.Animator:LoadAnimation(Char.GrabberReady)
local ReadyLoop = Humanoid.Animator:LoadAnimation(Char.GrabberReadyLoop)
local Attack = Humanoid.Animator:LoadAnimation(Char.GrabberAttack)
local State = 1
local GrabberPart = workspace:WaitForChild("GrabberSpawn")
local HRP = Char.PrimaryPart
local TweenService = game:GetService("TweenService")
local Distortion = Char.Head["FNaF 4 \"distortion\""]
local StartGrabberEvent = game.ReplicatedStorage.StartGrabber
local GrabberEscape = game.ReplicatedStorage.GrabberEscape
HRP.CFrame = GrabberPart.CFrame
HRP.Anchored = true


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		-------------------------------------

local JumpscareUI = player.PlayerGui:WaitForChild("Grabber").ImageLabel		
		
local JumpscareInfo = TweenInfo.new(
	1.5, -- Time
	Enum.EasingStyle.Quad, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local JumpscareTween = TweenService:Create(JumpscareUI, JumpscareInfo, {ImageTransparency = 1})
		
local JumpscareInfo2 = TweenInfo.new(
			.1, -- Time
			Enum.EasingStyle.Quad, -- EasingStyle
			Enum.EasingDirection.InOut, -- EasingDirection
			0, -- RepeatCount (when less than zero the tween will loop indefinitely)
			false, -- Reverses (tween will reverse once reaching it's goal)
			0 -- DelayTime
		)

		local JumpscareTween2 = TweenService:Create(JumpscareUI, JumpscareInfo2, {ImageTransparency = 0})
		
		local W = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberW")

		local A = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberA")

		local S = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberS")

		local D = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberD")
		


		
		
		
local function AttackPlayer()
			State = 3
			StartGrabberEvent:FireClient(player)
			Attack:Play()
			Distortion:Play()
			JumpscareTween2:Play()
			workspace.Boom:Play()
			JumpscareTween2.Completed:Connect(function()
				JumpscareTween:Play()
			end)
			Character.Humanoid.WalkSpeed = 0
			local BodyVelocityStun = Instance.new("BodyPosition")

			BodyVelocityStun.MaxForce = Vector3.new(10300, 10300, 10300)
			BodyVelocityStun.P = 10000
			BodyVelocityStun.Position = Vector3.new(-10.45, 21.2, 52)
			Character.HumanoidRootPart.CFrame = workspace.GrabberPlayer.CFrame
			BodyVelocityStun.Parent = Character.HumanoidRootPart
				game.Debris:AddItem(BodyVelocityStun, 1.5)
			GrabberEscape.OnServerEvent:Connect(function()
					BodyVelocityStun:Destroy()
				State = 1
				Distortion:Stop()
					Character.Humanoid.WalkSpeed = 8.5
				end)
	
		end
		if State == 1 then
			-------------------------------------
			local RandomState2Time = math.random(3.5, 20)

			local RandomAttackTime = math.random(0,5)
			-------------------------------------
		State = 1
		Idle:Play()
		task.wait(RandomState2Time)
		State = 2
		Ready:Play()
		Ready.Stopped:Connect(function()
			ReadyLoop:Play()
			task.wait(RandomAttackTime)
				AttackPlayer()
				ReadyLoop:Stop()
		end)
		end

	end)
end)

if you need more context, just ask

1 Like

Yeah, which lines coincide with you showing/hiding the Gui?

2 Likes

these are all in local script,

1 Like

Is there anything in the output? maybe try printing after each disable and see which ones don’t fire. It could be an error as well.

No errors, and i added print statements like this:
SERVER SCRIPT:

local Char = script.Parent
local Humanoid = Char.Humanoid
local Idle = Humanoid.Animator:LoadAnimation(Char.GrabberIdle)
local Ready = Humanoid.Animator:LoadAnimation(Char.GrabberReady)
local ReadyLoop = Humanoid.Animator:LoadAnimation(Char.GrabberReadyLoop)
local Attack = Humanoid.Animator:LoadAnimation(Char.GrabberAttack)
local State = game.ReplicatedStorage.GrabberState
local GrabberPart = workspace:WaitForChild("GrabberSpawn")
local HRP = Char.PrimaryPart
local TweenService = game:GetService("TweenService")
local Distortion = Char.Head["FNaF 4 \"distortion\""]
local StartGrabberEvent = game.ReplicatedStorage.StartGrabber
local GrabberEscape = game.ReplicatedStorage.GrabberEscape
HRP.CFrame = GrabberPart.CFrame
HRP.Anchored = true


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		-------------------------------------

local JumpscareUI = player.PlayerGui:WaitForChild("Grabber").ImageLabel		
		
local JumpscareInfo = TweenInfo.new(
	1.5, -- Time
	Enum.EasingStyle.Quad, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local JumpscareTween = TweenService:Create(JumpscareUI, JumpscareInfo, {ImageTransparency = 1})
		
local JumpscareInfo2 = TweenInfo.new(
			.1, -- Time
			Enum.EasingStyle.Quad, -- EasingStyle
			Enum.EasingDirection.InOut, -- EasingDirection
			0, -- RepeatCount (when less than zero the tween will loop indefinitely)
			false, -- Reverses (tween will reverse once reaching it's goal)
			0 -- DelayTime
		)

		local JumpscareTween2 = TweenService:Create(JumpscareUI, JumpscareInfo2, {ImageTransparency = 0})
		
		local W = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberW")

		local A = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberA")

		local S = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberS")

		local D = player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberD")
		


		
		
		
local function AttackPlayer()
			State.Value = 3
			StartGrabberEvent:FireClient(player)
			print("Player Got Attacked")
			Attack:Play()
			Distortion:Play()
			JumpscareTween2:Play()
			workspace.Boom:Play()
			JumpscareTween2.Completed:Connect(function()
				JumpscareTween:Play()
			end)
			Character.Humanoid.WalkSpeed = 0
			local BodyVelocityStun = Instance.new("BodyPosition")

			BodyVelocityStun.MaxForce = Vector3.new(10300, 10300, 10300)
			BodyVelocityStun.P = 10000
			BodyVelocityStun.Position = Vector3.new(-10.45, 21.2, 52)
			Character.HumanoidRootPart.CFrame = workspace.GrabberPlayer.CFrame
			BodyVelocityStun.Parent = Character.HumanoidRootPart
				game.Debris:AddItem(BodyVelocityStun, 1.5)
			GrabberEscape.OnServerEvent:Connect(function()
				print("Player has escaped")
					BodyVelocityStun:Destroy()
				State.Value = 1
				Distortion:Stop()
					Character.Humanoid.WalkSpeed = 8.5
				end)
	
		end
		State.Changed:Connect(function()
			-------------------------------------
			local RandomState2Time = math.random(3.5, 20)

			local RandomAttackTime = math.random(0,5)
			-------------------------------------
			State.Value = 1
		Idle:Play()
		task.wait(RandomState2Time)
			State.Value = 2
		Ready:Play()
		Ready.Stopped:Connect(function()
			ReadyLoop:Play()
			task.wait(RandomAttackTime)
				AttackPlayer()
				ReadyLoop:Stop()
		end)
		end)
		State.Value = 1
	end)
end)

LOCAL SCRIPT:

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local W = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberW")
local wKey = false
local wPressed = false
local A = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberA")
local aKey = false
local aPressed = false
local S = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberS")
local sKey = false
local sPressed = false
local D = Player.PlayerGui.EscapeGrabber:WaitForChild("EscapeGrabberD")
local dKey = false
local dPressed = false
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Combo = 0
local EscapeCombo = 2
local Sound = workspace["[SCP:CB] Button Click"]
local StartGrabberEscape = game.ReplicatedStorage.StartGrabberEscape.Value
local GrabberCombo = game.ReplicatedStorage.GrabberCombo
local StartGrabber = game.ReplicatedStorage.StartGrabber
local GrabberEscape = game.ReplicatedStorage.GrabberEscape
task.wait(1)
local EscapeDebounce = false
local Kick = Char.Humanoid.Animator:LoadAnimation(script.Kick)
local Camera = workspace.CurrentCamera
local CanPressKeys = true


function chooseKey()
	local ChosenKey = math.random(1,4)

	if ChosenKey == 1 then
		W.Enabled = true

		wKey = true
		aKey = false
		sKey = false
		dKey = false

		--
		wPressed = true
		aPressed = false
		sPressed = false
		dPressed = false

	elseif ChosenKey == 2 then
		wKey = false
		aKey = true
		sKey = false
		dKey = false

		A.Enabled = true
		--
		aPressed = true
		wPressed = false
		sPressed = false
		dPressed = false
	elseif ChosenKey == 3 then
		wKey = false
		aKey = false
		sKey = true
		dKey = false

		S.Enabled = true
		--
		sPressed = true
		wPressed = false
		aPressed = false
		dPressed = false
	elseif ChosenKey == 4 then
		wKey = false
		aKey = false
		sKey = false
		dKey = true

		D.Enabled = true
		--
		dPressed = true
		wPressed = false
		aPressed = false
		sPressed = false
	end
	

end


----------------------------------
StartGrabber.OnClientEvent:Connect(function()
	print("Client recieved attack, going to start the chooseKey() function")
	chooseKey()
	CanPressKeys = true
end)
----------------------------------
UIS.InputBegan:Connect(function(input, gpo)
	if Combo == EscapeCombo  then

		GrabberEscape:FireServer()
		print("Client: Fired to server that the player escaped.")
		CanPressKeys = false
		W.Enabled = false
		A.Enabled = false
		S.Enabled = false
		D.Enabled = false
		Kick:Play()
		Combo = 0

	end
end)
----------------------------------
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.W and wKey and CanPressKeys == true then

		Combo += 1
		Sound:Play()
		GrabberCombo.Value = Combo
	--[[
		Combotween:Play()
		Combotween.Completed:Connect(function()
			ComboUI.TextLabel.Text = "Combo: "..Combo
		end)
		KeyPressed = true
		--Wtween:Play()
		--Wtween2:Play()
		--Wtween.Completed:Wait()
		--]]
		W.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo  then
			chooseKey()
		end


	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.A and aKey and CanPressKeys == true  then
		Sound:Play()
		Combo += 1
		GrabberCombo.Value = Combo


		A.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo then
			chooseKey()
		end
	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.S and sKey and CanPressKeys == true  then
		Combo += 1
		Sound:Play()
		GrabberCombo.Value = Combo

		S.Enabled = false

		task.wait(.2)
		if Combo ~= EscapeCombo  then
			chooseKey()
		end
	end
end)
UIS.InputBegan:Connect(function(input, gpo)
	if gpo then return end
	if input.KeyCode == Enum.KeyCode.D and dKey and CanPressKeys == true  then
		Combo += 1
		GrabberCombo.Value = Combo
		Sound:Play()

		D.Enabled = false
		task.wait(.2)
		if Combo ~= EscapeCombo  then
			chooseKey()
		end
	end
end)

and all of them print, also the local script is in StarterGyu

The amounts of variables in those scripts literally lagged my computer. That’s probably why it won’t disable because a variable is broken, incorrect, or nil.

Tip: you can shorten the key changes/checking by applying a comparison boolean, like so:

wKey = ChosenKey == 1
aKey = ChosenKey == 2
sKey = ChosenKey == 3
dKey = ChosenKey == 4
wPressed = ChosenKey == 1
aPressed = ChosenKey == 2
sPressed = ChosenKey == 3
dPressed = ChosenKey == 4

Also consider storing booleans in a table. They dont need to be its own variable. Hope this helps!

Do you mean they don’t need to be their own local variable? Those would be a global variable.

how would the variable be broken if i use it in the script and it works that way?

so how should i implement that into the code

Your ChosenKey function would look like this:

local function chooseKey()
	local ChosenKey = math.random(1,4)
	wKey = ChosenKey == 1
	aKey = ChosenKey == 2
	sKey = ChosenKey == 3
	dKey = ChosenKey == 4
	wPressed = ChosenKey == 1
	aPressed = ChosenKey == 2
	sPressed = ChosenKey == 3
	dPressed = ChosenKey == 4
end

It would just be updating the variables at the top of the script. Not making new global variables.

the whole point of the if statements is to set things as true, and cancel eachother out, so that didnt work.

It didn’t? That’s odd.

Because if if ChosenKey == 1 then is returning true, then wKey = ChosenKey == 1 should make wKey be true. Otherwise if ChosenKey is not 1, then wKey should be false.

It would also be like doing:
wKey = (ChosenKey == 1 and true) or false

Oh and what I forgot in the previous post was changing:

W.Enabled = false
A.Enabled = false
S.Enabled = false
D.Enabled = false

to use the == 1 or == 2 stuff.

how would i implement

into this

i dont really think that is the solution

By broken, I basically meant something like nil. (:

the “W A S D” variables are not nil, checked by printing in both the local and server script

i solved it, i just had to change a few things.