Problem with my code

Hello! I am trying to make an automatic door opening system but the code isnt working. No errors are shown

local tweenservice = game:GetService(“TweenService”)

local db = false

local parent = script.Parent
parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and parent.Parent.Owner.Value ~= “nil” and db == false then
print(hit)
db = true
local properties1 = {
Position = script.Parent.Parent.Door2.Position
}
local properties2 = {
Position = script.Parent.Parent.Door1.Position
}

	local tweenfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
	local tween = tweenservice:Create(script.Parent.Parent.Door2, tweenfo, properties1)
	tween:Play()
	wait(0.2)
	
	wait(3)
	local tween2 = tweenservice:Create(script.Parent.Parent.Door2, tweenfo, properties2)
	tween2:Play()
	wait(0.2)
	db = false
	
end

end)

image

2 Likes

Unless you change it in another script or place, this will always be nil…

1 Like

can you format the code bettter by typing:

  • “```”
    your code
  • “```”
    (without the quotations or bullet points)
    (it should be the key above that tab button)

you are spot on its that condition that is most likely throwing a false

1 Like

Wait you set door 2 tween to door 2’s position so it doesn’t move at all, switch the variables

Also try doing this:

local properties1 = {}
properties1. Position =
script.Parent.Parent.Door2.Position

Thank you that was indeed the problem!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.