Seat Script Problem

I’m trying to make a seat that doesn’t allow you to sit unless you have a certain boolean value set to true, Which is called “Can Sit”.
The default is false and when I test it(I made sure my value is set to false) it doesn’t kick me off the seat.

script.Parent.ChildAdded:Connect(function(Seat)
	if Seat.Name == "SeatWeld" and Seat:IsA("Weld") then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Part1.Parent)
		if Player["Can Sit"] == false then
			Seat:Destroy()
		end
	end
end)

It doesn’t output any errors from this script, any help will be appreciated!

2 Likes

Why dont you get the players character, get the humanoid, and do

local hum = --blah blah 
hum.Sit = False

Screenshot 2024-11-27 at 9.35.29 AM

3 Likes

I think I got the Idea of what you meant, here’s what I wrote based on your suggestion:

script.Parent.ChildAdded:Connect(function(Seat)
	if Seat.Name == "SeatWeld" and Seat:IsA("Weld") then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Part1.Parent)
		if Player["Can Sit"] == false then
			Seat.Part1.Parent:FindFirstChild("Humanoid").Sit = false
		end
	end
end)

It didn’t work, and didn’t give any errors.

2 Likes

you could check for .PropertyChanged on the seat, because the occupant property of a chair/vehicle seat will always be the Character model that is in the chair, then tell the character’s humanoid to jump on sit if that value is false.

3 Likes

Is this on a local script?

abcdef

3 Likes

No it’s on a regular server wide one.

3 Likes

WAIT!!! Maybe it does work. The weld may be keeping the player in place!!! You may have to delete the weld. @Cteche

3 Likes

That’s what I originally did, didn’t work out.

3 Likes

But did you try it with the Sit = False?

3 Likes

I did also didn’t work out.eeee

3 Likes

Here it is @robloxhehevoice …eee

2 Likes

Can I see the whole script?

abcdefghij

3 Likes
script.Parent.PropertyChanged:Connect(function(Seat)
	if Seat.Name == "SeatWeld" and Seat:IsA("Weld") then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Part1.Parent)
		if Player["Can Sit"] == false then
			Seat.Part1.Parent:FindFirstChild("Humanoid").Sit = false
		end
	end
end)
2 Likes

Thats all of it?

abcdefghijklmnop

3 Likes

There’s no event called .PropertyChanged?

2 Likes

Yes, it’s parent is the seat itself.

3 Likes
script.Parent:GetAttributeChangedSignal("Occupant"):Connect(function(occupant)

end)
3 Likes

So, to start, why dont you put Print() statements on a few lines to see where it stops.

for ex.

script.Parent.PropertyChanged:Connect(function(Seat)
	if Seat.Name == "SeatWeld" and Seat:IsA("Weld") then
		local Player = game.Players:GetPlayerFromCharacter(Seat.Part1.Parent)
                Print("test#2")
		if Player["Can Sit"] == false then
			Seat.Part1.Parent:FindFirstChild("Humanoid").Sit = false
            Print("testing")
		end
	end
end)
1 Like

Also, is there supposed to be no dot between these two?

Screenshot 2024-11-27 at 9.50.20 AM

1 Like

No it gives me an error, when I try it.