Mobile/Tablet GUI not detecting sometimes

Hello, I have a GUI that enables when a mobile/tablet player sits in a vehicle seat. It usually works, but sometimes when the mobile player sits in the vehicle seat, the GUI fails to enable (seems to happen more with certain mobile devices than others). This is my script in the GUI in StarterGUI, any idea as to why it sometimes doesnt detect will help me out:

function activategui()
	if game.Players.LocalPlayer.Character.Humanoid.SeatPart == nil then
		script.Parent.Enabled = false
		script.Parent.Sub.Value = nil
		game.Players.LocalPlayer.TouchGui.Parent = game.Players.LocalPlayer.PlayerGui
		return
	end
	if game.Players.LocalPlayer.Character.Humanoid.SeatPart.ClassName == "VehicleSeat" then
		script.Parent.Enabled = true
		script.Parent.Sub.Value = game.Players.LocalPlayer.Character.Humanoid.SeatPart.Parent
		game.Players.LocalPlayer.PlayerGui.TouchGui.Parent = game.Players.LocalPlayer
	end
end

local UIS = game:GetService("UserInputService")
local GUI = game:GetService("GuiService")

game.Players.LocalPlayer.Character.Humanoid.Changed:Connect(function(plr)
	if plr == "SeatPart" and UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GUI:IsTenFootInterface() then
		activategui()
	end
end)

Hello! have you seen any errors from this script?
because sometimes when i do “game.Players.LocalPlayer.Character.Humanoid” it errors but if i add “:WaitForChild(“Humanoid”)” and change the localplayer thingy to local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() then it works try replacing those game.Players.LocalPlayer.PlayerGui.TouchGui and game.Players.LocalPlayer.Character.Humanoid

with :WaitForChild()

2 Likes

Thank you for your reply… i had no errors, and i actually had tried this while i was waiting for a reply because i had a hunch that since its sometimes not working but usually is, that it had to do with the script not detecting that the character loaded in sometimes. I am currently testing it and if its the cause (which I have a good feeling it is) i will mark yours as the solution.

If it still doesn’t work with what i have said in the previous reply then try adding “task.wait(5)
on the start of the detecting ui script so maybe thats the problem.

1 Like

Hehe i actually have a task.wait(1) in the beginning that i added, we think alike! I have been testing it the last two days with others joining and using mobile, so far so good. Will test few more days and then report my findings… thanks again for your help.

1 Like

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