Door goes up instead of staying in place

Im trying to make this door open and close depending on the rotation of this wheel. It wont work at all and ive tried many things. Ive revered the code back to how it used to be and now the door just flied up even though i didnt change anything.

Valve code:

game["Run Service"].Heartbeat:Connect(function()
		local SpinSpeed = Spinner.AssemblyAngularVelocity.Y
		Connected.Value.Trig:Fire(SpinSpeed)
	end)

Spinner is the valve and trig is the event

Door:

script.Parent.Trig.Event:Connect(function(Amt, Forward)
	script.Parent.Size -= Vector3.new(0, Amt/100, 0)
	script.Parent.Position += Vector3.new(0, Amt/100, 0)
end)

2 Likes

Since size changes in both directions youll have to add half of Amt/100. Like this:

script.Parent.Trig.Event:Connect(function(Amt, Forward)
	script.Parent.Size -= Vector3.new(0, Amt/100, 0)
	script.Parent.Position += Vector3.new(0, Amt/100/2, 0)
end)

Try that and tell me if it works or not

1 Like

Before worrying about that use TweenService. Is there some particular reason to avoid it?

1 Like

Now when the door is fully open it flies away, better but still bad

1 Like

How would i use tween service to open this kind of door…?

It depends on how you want the door to move, and right now I do not know what that is.

1 Like

i want the door to open/close in relation to the speed and rotation of the valve.

Can you be more specific? There are many ways for a door to open. Is it supposed to stay in place and shrink when opening?

Watch the video i sent if your confused

The video you sent is the door not working right? I want to know what you want it to be, not what it currently is.

Youll have to clamp the size and position:

local OriginalPosition = script.Parent.Position.Y
local OriginalSize = script.Parent.Size.Y
script.Parent.Trig.Event:Connect(function(Amt, Forward)
	script.Parent.Size -= Vector3.new(0, math.clamp(Amt/100,0,OriginalSize), 0)
	local clampedYPos = math.clamp(script.Parent.Position.Y+Amt/100/2,OriginalPosition.Y,OriginalPosition.Y+OriginalSize/2)
	script.Parent.Position =  Vector3.new(0,clampedYPos, 0)
end)]

At one point in the script you said “Size” did u mean Original size or what

Yes my bad, it should be OriginalSize ill fix it right away

No thats fine i can just do it myself

2 more issues have occured:

The door closes in on itself and i cant close the door by rotating the wheel the other way.

I noticed some typos in my code so maybe try this instead?:

local OriginalPosition = script.Parent.Position.Y
local OriginalSize = script.Parent.Size.Y
script.Parent.Trig.Event:Connect(function(Amt, Forward)
	script.Parent.Size -= Vector3.new(0, math.clamp(Amt/100,0,OriginalSize), 0)
	local clampedYPos = math.clamp(script.Parent.Position.Y+Amt/100/2,OriginalPosition,OriginalPosition+OriginalSize/2)
	script.Parent.Position =  Vector3.new(0,clampedYPos, 0)
end)]

it works but for some reason it moves the door like 50 studs away???

My bad i forgot to account for OriginalPosition.X and .Z it should be an easy fix:

local OriginalPosition = script.Parent.Position
local OriginalSize = script.Parent.Size.Y
script.Parent.Trig.Event:Connect(function(Amt, Forward)
	script.Parent.Size -= Vector3.new(0, math.clamp(Amt/100,0,OriginalSize), 0)
	local clampedYPos = math.clamp(script.Parent.Position.Y+Amt/100/2,OriginalPosition.Y,OriginalPosition.Y+OriginalSize/2)
	script.Parent.Position =  Vector3.new(OriginalPosition.X,clampedYPos, OriginalPosition.Z)
end)]

Now we are back to the door closing in on itself

My bad again lmao, i have edited my post with new code to not flood this post with more code