My door won't open help me out

Ello my fellow air breathing humans if you can help ya boy out in any way let me know so in short definition this is what I want -
What I want
I want the door to open by tween :sunglasses: but nah seriously I just want it when a player touches the door for it to open up
What I did
so I put this script in starterPlayerScripts because I want this to be local in the client I don’t want it to be in the server and I messed up the script since I’m new to scripting and would like some feedback on how I can fix it and learn!

The script:
Photo


In text

local debounce = false

for i,v in pairs(workspace.Door1) do
	v.Touched:connect(function(h)
		if h.Parent:FindFirstChild('LowerTorso') and debounce == false then
			print("Touched")
			debounce = true
			local TweenService = game:GetService("TweenService")
			local Info = TweenInfo.new( 
				1,
				Enum.EasingStyle.Quint,
				Enum.EasingDirection.Out,
				0,
				false,
				0
			)
			local Goals = {
				Position = Vector3.new(-1273.287, 50.945, 21110.467),
				Orientation = Vector3.new(0, -140, 0)
			}

			local MakeTheDoorOpen = TweenService:Create(v, Info, Goals)
			MakeTheDoorOpen:Play()

			debounce = false
	end

end)

Is this the entire script? I only see 2 ends but you should have 3. One for the loop, one for the touched function, and one for the if statement. Also, is the print working?

If I add another end I get an error like you know the red line I get that. And no the print doesn’t seem to work I guess it’s not identifying the door even though there is only one ā€œdoor1ā€ in the game

Is door1 a group with multiple parts or just one part?

Just one it’s a mesh. characters

I’m not sure if this is entire correct but you know that i, v in pairs only runs once so it might run before your even touching it. shouldn’t you put it in a loop or even a .touched function?

local player = game.Players.LocalPlayer
local door1 = workspace.Door1
local open = false
door1.Touched:Connect(function(hit)
   if hit.Parent.Name == player.Name and open == false then
      open = true
      local TweenService = game:GetService("TweenService")
      local Info = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
      local Goals = {
      Position = Vector3.new(-1273.287, 50.945, 21110.467),
      Orientation = Vector3.new(0, -140, 0)
      }
      local MakeTheDoorOpen = TweenService:Create(door1, Info, Goals)
      MakeTheDoorOpen:Play()
      MakeTheDoorOpen.Completed:Wait()
   end
end)

Well there is put v.Touched:Connect(function)(h)

Oof it’s still not working Characters

I didn’t test it or anything, any errors?

Yes but that is inside the i, v in pairs so it wont run like it would if it was outside.

You could do something like;

Door.touched:connect(function(h)
if h.Parent:FindFirstChild('LowerTorso') and debounce == false then
			print("Touched")
			debounce = true
			local TweenService = game:GetService("TweenService")
			local Info = TweenInfo.new( 
				1,
				Enum.EasingStyle.Quint,
				Enum.EasingDirection.Out,
				0,
				false,
				0
			)
			local Goals = {
				Position = Vector3.new(-1273.287, 50.945, 21110.467),
				Orientation = Vector3.new(0, -140, 0)
			}

			local MakeTheDoorOpen = TweenService:Create(v, Info, Goals)
			MakeTheDoorOpen:Play()

			debounce = false
	end
end)

It didn’t give any errors in the output it just didn’t work

I see an error in the first for loop. If Door1 is a group then you will need to do for i, v in pairs(workspace.Door1:GetChildren()) do

It’s a mesh it’s not in a group so idk

1 Like

Finally it worked! Thank you I figured it out through your script

3 Likes

You can’t use for i, v in pairs on a mesh. A for loop is only used to loop through a table of items. You don’t even need the for loop there, just remove it, define the door at the top local door = workspace.Door1 then instead of the for loop put door.Touched:Connect(function(hit)

Okay so I can’t use in pairs loops on meshes?

1 Like

No, you can only use them on an instance with things inside of it or a table. I would recommend watching this In Pairs Loops (i, v in pairs) - Roblox Beginner Scripting #18 - YouTube as he explains it in full detail.

This is because it is constantly looping through all of the instances inside, checking to see if a certain value has been set.

Okay! Thank you characters the

1 Like