I am making a sliding door thingy. Everything works, but I only want it to open if its in a certain place. The problem is when I click it nothing happens.

Any ideas?

local model = game.Workspace.BorderDoor

script.Parent.MouseClick:Connect(function(playerclicked)
	if model.MainPart.Position == Vector3.new(75.52, 14.85, 660.725) then	
		local pr = playerclicked:GetRankInGroup(4831829)
		if pr >= 10 then
			for i = 0,0.139,0.001 do
				model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
				wait()
			end
		end
	end
end)

3 comments

1

You're using too precise of numbers for position. You really might want to lower down the decimal placements, floating point errors do occur often

0

You might want to use booleans to control what's what. Whenever the sliding door is in the certain place change a boolean to true and do whatever while the boolean is true, then turn back false when it's not at the certain place anymore.

0

@123nabilben123 i did that and found that if you spammed the buttons you would end up launching door up or down. this was the only solution i could think of.