Detect boolean change in local script

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)
2 Likes

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)
2 Likes

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)
1 Like

Whoops I meant GetPropertyChangedSignal(). My bad. I’ve edited the original message LOL.

2 Likes

All good, do you know about the scipt working in starter player scripts but not in the part with the gui?

Can you explain this more in a new post?

1 Like

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