Need help with screen gui appearing after a player sits down on a certain seat

Hey I recently tried to make a seat that if a player sits on a screen gui appears with a mini game and I tried this code but it doesnt work and the error says player has no humanoid and when I checked inside the player it had no humanoid. Does anybody know how I can fix this?
This is a local script inside starter gui

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAppearanceLoaded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Seat = game.Workspace.Game.seat 
	local UI = game.StarterGui.ScreenGui

Humanoid.Seated:Connect(function(seated, seat)
	if seated and seat ==  Seat then
		--Player seated on correct seat
		UI.Enabled = true
	else
		--Player jumped away
		UI.Enabled = false
	end
end)

I’m still learning scripting and programming so I make lots of mistakes like this one but I don’t know how to fix this

You should be using “player gui”

local UI = player.PlayerGui.ScreenGui

I don’t know if this will solve the issue with the humanoid disappearing. You can also check to see if the seat has a seatweld in it.

2 Likes

Try this code instead. All I changed was:

  1. Don’t open the screen gui inside of StarterGui. Open it in PlayerGui, so the player will actually see it, as I don’t think opening it in StarterGui would replicate to the client.
  2. Use Player.Character or Player.CharacterAdded:Wait() when grabbing the player’s character instead. You really don’t need to wait for the appearance to load, unless it is important to your game, and besides, 'Player.CharacterAppearanceLoaded:Wait()` somehow didn’t work for me, so this might work for you.

That’s it! It should work as you want now!

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Seat = game.Workspace:WaitForChild("Game"):FindFirstChild("seat")

local UI = Player:WaitForChild("PlayerGui").ScreenGui

Humanoid.Seated:Connect(function(seated, seat)
	if seated and seat == Seat then
		UI.Enabled = true
	else
		UI.Enabled = false
	end
end)
2 Likes

Wait so where should I put the ScreenGui and this script inside the seat?
Also thanks for the fast reply

1 Like

Leave the ScreenGui in StarterGui, as anything in StarterGui clones into PlayerGui. I just said to access the ScreenGui in PlayerGui, so you can keep it in StarterGui. Also, what do you mean by “this script inside the seat”? Wasn’t this script a LocalScript in StarterGui? If I’m correct, you can just leave it there.

1 Like

Alright so my character doesnt exist and nothing works should I just give up?
I think my gui causes all this

Wait, is this a LocalScript inside of StarterGui, or am I getting confused?

1 Like

Its a screen gui with frame in it with more frames with buttons and images a flappy bird mini game

1 Like

Oh wait, my bad. To clarify, is the script with the code a LocalScript within StarterGui? Sorry for not clarifying earlier.

1 Like

Yes its a local script in starter gui

Can I see where the ScreenGui and the Seat is in Roblox Studio? A picture will do, but if you want to, you can send a video of the problem as well.

Sure the seat is in a model called game and the local script and gui are in starter gui (I dont know how to send a pic in reply)


Nevermind Im stupid

You know this doesnt make any sense I should make something instead but sorry for wasting your time

1 Like

Alright, good luck! Hope you succeed in your next goal :wink:

Thanks hope you have a nice day and sorry for wasting your time

1 Like