You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear! Trying to make it open the opposite direction from when the player is entering or leaving from the building.
-
What is the issue? Look on the video to find out what I am talking about - - YouTube
-
What solutions have you tried so far? I been trying to change the code and still haven’t got good luck.
I just want to find out why it doesn’t open in a certain direction depending on if they’re leaving or entering the building.
local ServerStorage = game.ServerStorage
local IsOpen = game.ServerStorage["Robberys"]["Jewelry Store"]["Status"]["IsOpen"]
local TimeAfterClose = 3
local LeftHinge = script.Parent.LeftDoor.PrimaryPart
local RightHinge = script.Parent.RightDoor.PrimaryPart
local Enter = script.Parent.Enter
local Leave = script.Parent.Leave
local opened = false
local connection
local connection2
-- Fires when the player trys to enter the building
function OpenDoor1(hit,player)
if hit.Parent:FindFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
if connection then
connection:Disconnect()
if not opened and IsOpen.Value then
opened = true
for i = 1, 18 do
script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
game:GetService("RunService").Stepped:Wait()
end
wait(TimeAfterClose)
for i = 1, 18 do
script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
game:GetService("RunService").Stepped:Wait()
end
opened = false
wait(0.5)
connection = Enter.Touched:Connect(OpenDoor1)
end
end
end
end
end
-- Fires when the player trys to leave the building
function OpenDoor2(hit,player)
if hit.Parent:FindFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
if connection2 then
connection2:Disconnect()
if opened == false then
opened = true
for i = 1, 18 do
script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
game:GetService("RunService").Stepped:Wait()
end
wait(TimeAfterClose)
for i = 1, 18 do
script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
game:GetService("RunService").Stepped:Wait()
end
opened = false
wait(0.5)
connection2 = Leave.Touched:Connect(OpenDoor2)
end
end
end
end
end
connection = Enter.Touched:Connect(OpenDoor1)
connection2 = Leave.Touched:Connect(OpenDoor2)