Hi guys, I’m not particularly sure on how to set up my repeat loop so that the two lines below it actually work. Here’s my current code:
local PlayerModule = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local controls = PlayerModule:GetControls()
controls:Disable()
local GPC = game:GetService("GamepadService")
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Frame = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Drawing")
repeat
wait()
until (what do i add here!!!!)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
GPC:EnableGamepadCursor(Frame)
Hopefully someone knows what to do, especially since I feel like there’s an easy fix as well
(Also this does work if I allow a small wait time, but I’d like a more accurate solution.)
I recommend using while loops instead since they are more customizable.
You usually run them until a certain statement is true. What exactly are you trying to wait for?
“Break” signals that the loop should stop.
while true do
task.wait()
if 2 + 3 == 5 then break end
end
I actually think I had a similar issue with the reset button. This is taken straight from my game. “Pcall” checks if the line will error, and if it errors, then the loop tries again until it succesfully turns off the reset button.
Let me know if this fixes it.
local function DisableResetButton()
while true do
local success,response = pcall(StarterGui.SetCore,StarterGui,"ResetButtonCallback",false)
if success then break end
task.wait()
end
end
DisableResetButton()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
There no need of any delay
you already used WaitForChild
here is improved version of your script:
local Players = game:GetService("Players")
local GPC = game:GetService("GamepadService")
local StarterGui = game:GetService("StartedGui")
local RunService = game:GetService("RunService")
local Heartbeat = RunService.Heartbeat
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")::PlayerGui
local PlayerModule = require(Player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local controls = PlayerModule:GetControls()
controls:Disable()
local Frame = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Drawing")
local success:boolean = pcall(StarterGui.SetCoreGuiEnabled,StarterGui,Enum.CoreGuiType.All, false)
while not success do
success= pcall(StarterGui.SetCoreGuiEnabled,StarterGui,Enum.CoreGuiType.All, false)
Heartbeat:Wait()
end
GPC:EnableGamepadCursor(Frame)
Yeah no so what I would recommend is something along these lines:
local coreCall do
local MAX_RETRIES = 8
local StarterGui = game:GetService('StarterGui')
local RunService = game:GetService('RunService')
function coreCall(method, ...)
local result = {}
for retries = 1, MAX_RETRIES do
result = {pcall(StarterGui[method], StarterGui, ...)}
if result[1] then
break
end
RunService.Stepped:Wait()
end
return unpack(result)
end
end
Guys I managed to figure it out, it was really as simple as I thought
local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Keyboard
local Touch
local Gamepad
local PlayerModule = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local controls = PlayerModule:GetControls()
controls:Disable()
local GPC = game:GetService("GamepadService")
local PlayerGui = Player:WaitForChild("PlayerGui")
local Frame = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Drawing")
local function key()
Keyboard = true
Touch = false
Gamepad = false
GPC:DisableGamepadCursor()
print("Keyboard")
end
local function touch()
Keyboard = false
Touch = true
Gamepad = false
GPC:DisableGamepadCursor()
print("Touch")
end
local function gamepad()
Keyboard = false
Touch = false
Gamepad = true
print("Gamepad")
if GPC.GamepadCursorEnabled then return end
GPC:EnableGamepadCursor(Frame)
end
if UIS.VREnabled then
gamepad()
print("VR")
elseif UIS.TouchEnabled and not UIS.KeyboardEnabled then
touch()
print("Phone")
elseif UIS.GamepadEnabled and not UIS.KeyboardEnabled then
gamepad()
print("Console")
elseif UIS.KeyboardEnabled then
key()
print("PC")
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.MouseButton2 or input.UserInputType == Enum.UserInputType.MouseButton3 or input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.MouseWheel then
if not Keyboard then
key()
end
elseif input.UserInputType == Enum.UserInputType.Touch then
if not Touch then
touch()
end
elseif input.UserInputType == Enum.UserInputType.Gamepad1 or input.UserInputType == Enum.UserInputType.Gamepad2 or input.UserInputType == Enum.UserInputType.Gamepad3 or input.UserInputType == Enum.UserInputType.Gamepad4 or input.UserInputType == Enum.UserInputType.Gamepad5 or input.UserInputType == Enum.UserInputType.Gamepad6 or input.UserInputType == Enum.UserInputType.Gamepad7 or input.UserInputType == Enum.UserInputType.Gamepad8 then
if not Gamepad then
gamepad()
end
end
end)
UIS.InputChanged:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Thumbstick1 or input.KeyCode == Enum.KeyCode.Thumbstick2 then
gamepad()
end
end)
GPC:EnableGamepadCursor(Frame)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
I realised it didnt work since my emulator initially recognises roblox as a pc app so the virtual mouse never actually showed.
Thanks everyone for your help though, sorry for taking up so much time