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

Whats wrong with my script?

if script.Parent.Position == Vector3.new(-74.5, 7.5, 19.5) then
script.Parent.ClickDetector.MouseClick:connect(function()
	game.Workspace.Door.Position = Vector3.new(-80,5.5,25)
	game.Workspace.Door.Rotation = Vector3.new(-180,0,-180)
    script.Parent.Position = Vector3.new(-81.5, 7.5, 23.5)
    script.Parent.Rotation = Vector3.new(0, 90, 0)
elseif script.Parent.Position == Vector3.new(-74.5, 7.5, 19.5) then
script.Parent.ClickDetector.MouseClick:connect(function()
	game.Workspace.Door.Rotation = Vector3.new(0,90,0)
	game.Workspace.Door.Position = Vector3.new(-76, 5.5, 21)
    script.Parent.Position = Vector3.new(-74.5, 8.5, 19.5)
    script.Parent.Rotation = Vector3.new(0, 90, 0)	
end)
end
**If you can tell it is for a door that opens and closes please help**

3 comments

0

Where is your error?

0

Its just not working, I'm trying to make a door move forwards then backwards by changing its position. This also has the handle changing. If you have a better way of doing it or know how to fix it please tell me.

0

I'm not a king at Vectors and etc but i think CFrame.new should replace the Vector3. and Try that

1 answer

✓ Accepted answer

Your problem is that you're trying to make a conditional to activate your event. This won't work, the event will activate reguardless of whether or not the condition returns true or false.

Also, both your conditions are the same.. so the door will always just open

Try putting the conditionals inside the event. And makeing a bool switch to check if the door is open or closed.

local open = false

script.Parent.ClickDetector.MouseClick:connect(function()
	if open then open = false
		workspace.Door.Position = Vector3.new(-80,5.5,25)
		workspace.Door.Rotation = Vector3.new(-180,0,-180)
		script.Parent.Position = Vector3.new(-81.5, 7.5, 23.5)
		script.Parent.Rotation = Vector3.new(0, 90, 0)
	else open = true
		workspace.Door.Rotation = Vector3.new(0,90,0)
		workspace.Door.Position = Vector3.new(-76, 5.5, 21)
		script.Parent.Position = Vector3.new(-74.5, 8.5, 19.5)
		script.Parent.Rotation = Vector3.new(0, 90, 0)  
	end
end)

1 comment

0

thankyou!

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