Opening gui works in studio but wont in roblox

https://youtu.be/CB7dKpYzbLo —when it shows the ui appearing thats when i first spawned, after a pause it shows me not doing any thing with gun, but im pressing the keycode that opens the ui and it wont open it

so the opening gui only works if i spawn first, but if i die, and i try it again, it doesnt work any work which is weird since in studio when i die it still works

userinput.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.ButtonX then
			if tool:IsDescendantOf(player.Character) and hum and STOP == false then
				reload()
			end
		end
	
		if input.UserInputType == Enum.UserInputType.MouseButton2 or input.KeyCode == Enum.KeyCode.ButtonB then
			if tool:IsDescendantOf(player.Character) and hum and STOP == false and reloading == false then
				aimss()
			end
		end
		if input.KeyCode == Enum.KeyCode.T  or input.KeyCode == Enum.KeyCode.ButtonY then
			if  tool:IsDescendantOf(player.Character)and debounce == false and hum and reloading == false and aim == false then debounce = true
				chamberrr()
				end
		end

		if input.KeyCode == Enum.KeyCode.J and  tool:IsDescendantOf(player.Character) then   ---this is where the opening ui start
			print("okai i open")
			if hum and reloading == false and openit == false then
				print("okai it see")
				gunselction:WaitForChild("Frame").Visible = true
				openit = true
			else
				if openit == true then
					gunselction:WaitForChild("Frame").Visible = false
					openit = false

				end
			end
		end
		end
	
end)
2 Likes

In the screen Gui is “ResetOnSpawn” enabled? Would you mind showing the full script?

1 Like

I recommend using the InputAction system from Roblox or creating a dictionary to batch the logic since if checks are getting incredibly inefficient past 2 if statements

yeah its enabled,

local gunselction = player.PlayerGui:WaitForChild("gunselection")
local openit = false



userinput.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.ButtonX then
			if tool:IsDescendantOf(player.Character) and hum and STOP == false then
				reload()
			end
		end
		if input.KeyCode == Enum.KeyCode.Y or input.KeyCode == Enum.KeyCode.ButtonL2 then
			if tool:IsDescendantOf(player.Character) and hum and STOP == false and reloading == false then
				checkammo()
			end
		end
		if input.UserInputType == Enum.UserInputType.MouseButton2 or input.KeyCode == Enum.KeyCode.ButtonB then
			if tool:IsDescendantOf(player.Character) and hum and STOP == false and reloading == false then
				aimss()
			end
		end
		if input.KeyCode == Enum.KeyCode.T  or input.KeyCode == Enum.KeyCode.ButtonY then
			if  tool:IsDescendantOf(player.Character) and debounce == false and hum and reloading == false then debounce = true
				chamberrr()
				end
			end		
		if input.KeyCode == Enum.KeyCode.J and  tool:IsDescendantOf(player.Character) then
				if hum and reloading == false and openit == false then 
				gunselction:WaitForChild("Frame").Visible = true
				openit = true
			else
				if openit == true then
					gunselction:WaitForChild("Frame").Visible = false
						openit = false
					end
				end
				
			end
		end
	
end)

hmm ive never heard of it, il try to learn it

Set reset on spawn to false, and see if it works.

1 Like

Alrighty ill try dojng thaaaa…

1 Like

yayyy it worked!!, thank u !! charsssssss

Perfect!! Good luck with what you are working on!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.