I am trying to detect when the sit value in the player humanoid changes but I keep getting “attempt to index boolean with ‘Changed’”, how do I detect it? (Also this script is in starter player scripts but I want it in the part that has the gui but when I put it their it stops working, any thoughts?)
Local Script
local chair0 = game.Workspace.Room.Group1:WaitForChild("Chair")
local chair1 = game.Workspace.Room.Group1:WaitForChild("Chair1")
local player = game.Players.LocalPlayer
local seat0 = chair0:WaitForChild("Seat").Occupant
local seat1 = chair1:WaitForChild("Seat").Occupant
local plrName = player.Name
local value = game.Workspace[plrName].Humanoid.Sit
value.Changed:Connect(function()
print(game.Workspace[player.Name].Humanoid.Sit.Value)
if seat0 == player.Name or seat1 == player.Name then
game.Workspace.Room.Group1.Button.Base.BillboardGui.TextLabel.Text = "Waiting For Players..."
elseif seat0 ~= player.Name and seat1 ~= player.Name then
game.Workspace.Room.Group1.Button.Base.BillboardGui.TextLabel.Text = "Sit to play"
end
end)
This is because Sit is a property (like color, size, position etc.) of the humanoid. When you set it to a variable, you are essentially setting the variable equal to whatever the value of Sit is at that moment. What you want to do instead is to use the :GetPropertyChangedSignal() on the Humanoid to detect when the property Sit changes. This would look something like:
humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
-- Do Stuff
end)
GetPropertyChangedEvent is not a valid member of Humanoid “Workspace.SuperEmeraldMaster1.Humanoid”
local chair0 = game.Workspace.Room.Group1:WaitForChild("Chair")
local chair1 = game.Workspace.Room.Group1:WaitForChild("Chair1")
local player = game.Players.LocalPlayer
local seat0 = chair0:WaitForChild("Seat").Occupant
local seat1 = chair1:WaitForChild("Seat").Occupant
local plrName = player.Name
local humanoid = game.Workspace[plrName].Humanoid
humanoid:GetPropertyChangedEvent("Sit"):Connect(function()
if seat0 == player.Name or seat1 == player.Name then
game.Workspace.Room.Group1.Button.Base.BillboardGui.TextLabel.Text = "Waiting For Players..."
elseif seat0 ~= player.Name and seat1 ~= player.Name then
game.Workspace.Room.Group1.Button.Base.BillboardGui.TextLabel.Text = "Sit to play"
end
end)