Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Door that moves (with button) not sure what I did wrong?

new problem, right so

DoorHold = game.Workspace.doorfather.DoorHold

local open=true
local door = script.Parent.Parent
script.Parent.mouseClick:connect(function()
    if open then 
        open=false
    door.CFrame = CFrame.new(DoorHold.Position)
        door.BrickColor=script.PartkeypadY.Value
    else
        open=true
        door.CFrame = CFrame.new(TargetPosition + Vector3.new(0,10,0))
        door.BrickColor=script.PartkeypadX.Value
    end
end)


these are photos of where all my stuff is located

i get the error

22:05:58.124 - Stack End 22:06:06.191 - Position is not a valid member of Model 22:06:06.192 - Stack Begin 22:06:06.193 - Script 'Workspace.doorfather.Keypad.Partkeypad.ClickDetector.Script', Line 8

5 comments

0

What is Doorgay is Doorgay a value or something if not and it is just a name game.Workspace.Doorgay or make it a variable

0

doorgay is a part that is a door that is supposed to open when you press the button

0

In that case then do local Doorgay = game.Workspace.Doorgay (considering that is where the part is)

0

i will reply to you with where all my parts are http://imgur.com/a/mWC37

0

you should be able to figure it out just do something.something.something(that holds doorgay).Doorgay

2 answers

Problem: probably that you aren't assigning to .Position on lines 6 or 12. Also note that using CFrame is much better, since if someone's standing in the door, CFrame will ignore them and "close" it anyway (preventing people from keeping it open indefinitely).

Minor notes:

  • You have a lot of script.Parent.Parent. Consider replacing that with a variable (like "door" or "house" or "model" or whatever it is). As farrizbb suggests, you might also consider making the more specific variables.
  • You never need to say + Vector3.new(0, 0, 0), as anything plus zero is unchanged
  • You don't need to say "== true". By default, any non-false/nil value is considered true.
  • Using local variables is slightly faster and good practice to be in

Resulting script:

local open=true
local door = script.Parent.Parent
script.Parent.mouseClick:connect(function()
    if open then 
        open=false
	door.CFrame = CFrame.new(Doorgay.Position)
        door.BrickColor=script.ButtonY.Value
    else
        open=true
       	door.CFrame = CFrame.new(TargetPosition + Vector3.new(0,10,0))
        door.BrickColor=script.ButtonX.Value
    end
end)

Notice the significant decrease in the amount of text you have to read/write. Further, it is easy to modify the variables in the first two lines (ex maybe the script is moved to a different location and you only need to access script.Parent instead of script.Parent.Parent -- in that case, you can do that in a single location (line 2) instead of several).

10 comments

0

21:58:14.084 - Workspace.doorfather.Keypad.Partkeypad.ClickDetector.Script:6: attempt to index global 'Doorgay' (a nil value) 21:58:14.086 - Stack Begin 21:58:14.087 - Script 'Workspace.doorfather.Keypad.Partkeypad.ClickDetector.Script', Line 6 21:58:14.088 - Stack End

0

Are you just copy and pasting the script or reading it then copy and pasting .

0

DoorHold = game.Workspace.doorfather.DoorHold local open=true local door = script.Parent.Parent script.Parent.mouseClick:connect(function() if open then open=false door.CFrame = CFrame.new(DoorHold.Position) door.BrickColor=script.PartkeypadY.Value else open=true door.CFrame = CFrame.new(TargetPosition + Vector3.new(0,10,0)) door.BrickColor=scr

0

the scripts keep cutting off, in this section for this line door.CFrame = CFrame.new(DoorHold.Position) it says 22:06:06.191 - Position is not a valid member of Model

0

i just edited the question, i need help for that now

0

Kinda hard to explain it since you haven't gotten up to what we've been talking about so loom it up on wiki

0

so what would i look up on the wiki?

0

clckdetector

0

You can't position a model correct?

0

@TheePBHST Correct, if it's a model it should be :MoveTo(position) instead of .Position = position

I have figured it out with the help of the friendly people on the discord. thanks.

local Buttons = {}
for _,a in pairs(script.Parent.Parent.Parent.Button:GetChildren()) do
    if a:IsA('BasePart') then
        table.insert(Buttons, a)
    end
end
local ClickDetector = Instance.new('ClickDetector')
for _,a in ipairs(Buttons) do
	local ClickDetector = Instance.new('ClickDetector', a)
	ClickDetector.MouseClick:connect(function()
		if script.DoorOpen.Value == false then
			script.DoorOpen.Value = true
   			print('Opening Door')
    		for i = 1,25 do
      			for _,a in ipairs(script.Parent.Parent.Parent.DoorHold:GetChildren()) do
					a.CFrame = (a.CFrame + (Vector3.new(0,0.5,0)))
           			wait()
        		end
			end
		else
			script.DoorOpen.Value = false
			 print('Closing Door')
    		for i = 1,25 do
    		    for _,a in ipairs(script.Parent.Parent.Parent.DoorHold:GetChildren()) do
					a.CFrame = (a.CFrame - (Vector3.new(0,0.5,0)))
					wait()
        		end
			end
    	end	
	end)
end

print(#Buttons)

This discussion is preserved as it was. New answers, comments, and votes are closed.