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)
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
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)