Door script not working?

I am trying to make a script where when you click a button, it changes the size of the door part so players can walk through it. I am getting the error “X can not be assigned to”. Can anyone help?

function onClicked()
script.Parent.Parent.Part.Size.X = script.Parent.Parent.Part.Size.X - 5
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 Like

Try using this:

local Size = -- size

function Clicked(Door)
script.Parent.Parent.Part.Size = Vector3.new(Size)
end

script.Parent.ClickDetector.MouseClick:connect(Clicked)

You can’t change the X in a Vector3 value. Just change the size with Vector3.new(X, Y, Z).

would you know how to make it change that value until the door is not there anymore? As in making it like a sliding door?

Just do this.

script.Parent.Parent.Part.Size = script.Parent.Parent.Part.Size - Vector3.new(5, 0, 0)

Also last question, do you know how to make it repeat a certain amount of times?

You’d have to use for loops

for i = 1, n do --n is the amount of times it's going to loop
    --your code
end
1 Like

ah yes I forgot about that way! thank you!

local amountOfTimes = 10 --Change this to the number of times

for count = 1, amountOfTimes do
    script.Parent.Parent.Part.Size = script.Parent.Parent.Part.Size - Vector3.new(5, 0, 0)
end

It’s as simple as making a for loop.

1 Like