How to make model disappearing upon sitting?

Heyo! If you’re a scripter and reading this, I need some help with a seat script that allows a certain part to disappear if a player sits.


So how it would work is that the tossed chair on the left is the starting point, and if someone were to sit on the invisible seat around that area, the chair on the ground will disappear and the one that the dummy is sitting on would appear. I don’t have any scripting experience so I could really use some help :pensive:

Edit: I’m also trying to re-use this script so you would be helping me alot in future projects.

1 Like

Use GetPropertyChanedSignal with the Occupant property of the seat.

(After rereading your post and seeing that you have no scripting experience, you may want to ask someone elsewhere to make the script for you. This is not a place for hiring.)

You could try this

local oldchair = chairontheground — change this to the chair laying on the ground
local newchair = chairstandingup — change this to the chair the player is sitting on
local seat = seat — change this to the seat part

seat:GetPropertyChangedSignal(“Occupant”):Connect(function(player)
      if player ~= nil then
            for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end
      else

for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end
      end
end)

I think this will work. I have no way to test right now. It’s a bit messy cause I had to type it out on my phone

Sadly didn’t work and the problem is location. Where exactly do I place the script? Originally had it in the seat and even with seperating them, I have no luck.
Photos:
image

It because you haven’t set the variable to the parts. So create a group and put both chair models in that group as well as the script. Then set the new chair variable to script.Parent.NewChair And set the old chair variable to script.Parent.OldChair And set the seat variable to NewChair.Seat

Very sorry but I don’t think I understood what you meant exactly because I re-wrote the scripts you told me to, but still no luck.


image
edit: spent 20 minutes trying new ways :sob:

Because you deleted the variables. Just copy an paste this into that script and it should work👍


local oldchair = script.Parent.OldChair
local newchair = script.Parent.NewChair
local seat = newchair.Seat
seat:GetPropertyChangedSignal(“Occupant”):Connect(function(player)
      if player ~= nil then
            for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end
      else

for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end
      end
end) 

You are doing it wrong. It should look like this:

local oldchair = script.Parent.OldChair
local newchair = script.Parent.NewChair
local seat = newchair.Seat
seat:GetPropertyChangedSignal(“Occupant”):Connect(function()
   local player = seat.Occupant ~= nil and game.Players:GetPlayerFromCharacter(seat.Occupant.Parent)
      if player then
            for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end
      else

for i,parts in ipairs(oldchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 0
                        parts.CanCollide = true
                  end
            end

           for i,parts in ipairs(newchair:GetDecedents()) do
                  if parts:IsA(“BasePart”) then
                        parts.Transparency = 1
                        parts.CanCollide = false
                  end
            end
      end
end)

From what I can see, all you did is remove the “player” variable that the function uses. Please explain the changes you make instead of just saying “you are doing it wrong”.

There is no such variable in that function. (So it will always be nil and the script will not work)

1 Like

I see, well if what you said true then I need a little fixing with where I locate things, because I added yours but I’m not sure I placed the seat in the right position to enable the script


Proof of the change ^

image
Current state of the grouped models

and I’ve also taken the Seat out of both chair groups entirely, Place the seat into the script and vice versa and nothing has changed.

Just retype the quotation marks and the stuff within them. For whatever reason when you copy and paste stuff, the script does not register string values (the stuff inside the quotation marks)

1 Like

Do you mind sending a copy of the place with the scripts inside the chair?

ChairScript.rbxm (15.6 KB)

Did so, but decided to check and output and…

It should be GetDescendants, not GetDescedents.

1 Like

Since I’m on my phone i may have spelt it wrong

Here try this its an edited and updated version of @thebossnnoy

local oldchair = script.Parent:WaitForChild("OldChair")
local newchair = script.Parent:WaitForChild("NewChair")
local seat = newchair:WaitForChild("Seat")

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local player = seat.Occupant and  game.Players:GetPlayerFromCharacter(seat.Occupant.Parent)
	if player then
		for _,parts in pairs(oldchair:GetChildren()) do
			if parts:IsA("BasePart") then
				parts.Transparency = 1
				parts.CanCollide = false
			end
		end
		for _,parts in pairs(newchair:GetChildren()) do
			if parts:IsA("BasePart") then
				parts.Transparency = 0
				parts.CanCollide = true
			end
		end	
	else
		for _,parts in pairs(oldchair:GetChildren()) do
			if parts:IsA("BasePart") then
				parts.Transparency = 0
				parts.CanCollide = true
			end
		end
		for _,parts in pairs(newchair:GetChildren()) do
			if parts:IsA("BasePart") then
				parts.Transparency = 1
				parts.CanCollide = false
			end
		end
	end
end)
1 Like

It works! I’d like to take the time and thank you all for your help.

2 Likes

I noticed you used in pairs instead of in ipairs. Why is that?