Hi, I have the following scripts that operate key doors but when streaming enabled is in use, it cant find the objects to work with. Is there a way to make this global script only when the player is in proximity of a door without adding an extra script to the door? would having a script running with “magnitude” be too inefficient?
here is the script, thank you very much for looking at it:
local Doors = game.Workspace.Doors:GetChildren()
local AmountOfDoors = #Doors
local Player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local Debounce = false
for i,v in pairs(game.Workspace.Doors:GetChildren()) do
v.KeyReader.BackGround.Attachment2.ProximityPrompt.Triggered:Connect(function()
local KeyCardName = v:GetAttribute("KeyCard")
if Player.Backpack:FindFirstChild(KeyCardName) or Player.Character:FindFirstChild(KeyCardName) then
if v:GetAttribute("Status") == false then
v:SetAttribute("Status", true)
local part1 = v.Part1
local goal = {}
-- goal.Position = Vector3.new(-95.7, 5.36, -8)
goal.Position = part1.Position
local Info = TweenInfo.new(v:GetAttribute("TimeUp"))
local Tween = TweenService:Create(v.Door, Info, goal)
Tween:Play()
v.KeyReader.BackGround.Attachment.ProximityPrompt.Enabled = true
else
v:SetAttribute("Status", false)
local goal = {}
-- goal.Position = Vector3.new(-89.5, 5.36, -8)
goal.Position = v.KeyReader.BackGround.Position
local Info = TweenInfo.new(v:GetAttribute("TimeDown"))
local Tween = TweenService:Create(v.Door, Info, goal)
Tween:Play()
end
end
end)
v.KeyReader.BackGround.Attachment.ProximityPrompt.Triggered:Connect(function()
local KeyCardName = v:GetAttribute("KeyCard")
if Player.Backpack:FindFirstChild(KeyCardName) or Player.Character:FindFirstChild(KeyCardName) then
if v:GetAttribute("Status") == false then
v:SetAttribute("Status", true)
local part1 = v.Part1
local goal = {}
-- goal.Position = Vector3.new(-95.7, 5.36, -8)
goal.Position = part1.Position --Vector3.new(9.963, 5.375, 35.507)
local Info = TweenInfo.new(v:GetAttribute("TimeUp"))
local Tween = TweenService:Create(v.Door, Info, goal)
Tween:Play()
v.KeyReader.BackGround.Attachment.ProximityPrompt.Enabled = v:GetAttribute("OutPromptAfterOpen") --false
v.KeyReader.BackGround.Attachment2.ProximityPrompt.Enabled = v:GetAttribute("InnerProxPresent")
else
v:SetAttribute("Status", false)
local goal = {}
-- goal.Position = Vector3.new(-89.5, 5.36, -8)
goal.Position = v.KeyReader.BackGround.Position --Vector3.new(9.963, 5.375, 35.507)
local Info = TweenInfo.new(v:GetAttribute("TimeDown"))
local Tween = TweenService:Create(v.Door, Info, goal)
Tween:Play()
end
end
end)
end