So i’m writing a script that enables a door to open but I can’t find out how to get the code to work, it was working earlier but I had to move the script to a new folder to sort it out
I tried to like move around the parts to see if the grouping was wrong and stuff, but it was so complicated and I couldn’t figure it out. Please help!
local StringValue = script:FindFirstChild("Status")
local TweenService = game:GetService("TweenService")
local DoorClose = {}
DoorClose.CFrame = door.CFrame * CFrame.new(0,-9,0)
local DoorOpen = {}
DoorOpen.CFrame = door.CFrame
local Doortime = TweenInfo.new(0.5)
local dooropen = TweenService:Create(door,Doortime,DoorOpen)
local doorclose = TweenService:Create(door,Doortime,DoorClose)
local dooropen = TweenService:Create(door,Doortime,DoorOpen)
local clickdetector = script.Parent:WaitForChild("ClickDetector3")
clickdetector.MouseClick:Connect(function()
if StringValue.Value == "OPENED" then
doorclose:Play()
StringValue.Value = "CLOSED"
script.Parent.Material = Enum.Material.Neon
script.Parent.BrickColor = BrickColor.Red()
elseif StringValue.Value == "CLOSED" then
dooropen:Play()
script.Parent.Material = Enum.Material.Neon
script.Parent.BrickColor = BrickColor.Green()
StringValue.Value = "OPENED"
end
end)
workspace.Folder2.Button2.ButtonScript2.ClickDetector3.MouseClick:Connect(function()
game.SoundService.Open:Play()
end)
Always have a habit of putting scripts inside of an instance instead of putting instances inside of a script i.e having no instances under a script.
Just drag the ClickDetector3 and put it under Button2. That will fix the error. For better placement of the instance, you can keep the script under ClickDetector3 and make necessary changes in your script and in order to access the ClickDetector3 in that way, it will be script.Parent
I tried @DesfellLavaway solution. It helped I think, but the script doesn’t completely work. I also forget to say that I want it to play a sound when the door opens, but it does not work and gives me errors.
The Script:
local Stringvalue = script:FindFirstChild("Status")
local TweenService = game:GetService("TweenService")
local DoorClose = {}
DoorClose.CFrame = door.CFrame * CFrame.new(0,-8,500,0)
local DoorOpen = {}
DoorOpen.CFrame = door.CFrame
local Doortime = TweenInfo.new(0.5)
local dooropen = TweenService:Create(door,Doortime,DoorOpen)
local doorclose = TweenService:Create(door,Doortime,DoorClose)
local dooropen = TweenService:Create(door,Doortime,DoorOpen)
local clickdetector = script:WaitForChild("ClickDetector3")
clickdetector.MouseClick:Connect(function()
if Stringvalue.Value == "OPENED" then
doorclose:Play()
Stringvalue.value = "CLOSED"
script.Parent.Material = Enum.Material.Neon
script.Parent.BrickColor = BrickColor.Green()
elseif Stringvalue.Value == "CLOSED" then
dooropen:Play()
script.Parent.Material = Enum.Material.Glass
script.Parent.BrickColor = BrickColor.White()
Stringvalue.Value = "OPENED"
end
workspace.Folder2.Button2.ButtonScript2:WaitForChild("ClickDetector3")
game.SoundService.Open:Play()
end)
you have 4 arguments in the cframe doohickey, a cframe is a combination of orientation and position.
So what you’d need to do is just remove one of those digits, but that’ll just error with “vector3 expected, got cframe”, but aswell as removing one, do DoorClose.CFrame = door.CFrame * CFrame.new(x:-8,y:500,z:0) remember its XYZ, and this will NOT have any orientation added to it.
if you want to add orientation, you need to have it tween to another parts CFrame or add in another tween for its orientation.
I’ve always just tweened it to an invisible parts CFrame because im dumb but, its easy and it works