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