When I activate one proximity prompt, it breaks the other ones…
I’m trying to make a light switch turn the lights on with proximity prompts,
I am using modules to do this.
Weirdly, when I turn one light switch on, It breaks all other light switches causing them to do nothing.
This is a Video of the Issue:
https://youtu.be/Xe-orUOijkU
Module for tween:
local module = {}
--Variables
local Opened = false
--Functions
function module.Open (prox:ProximityPrompt, plr:Player)
local Door = prox.Parent.Parent.Parent
if prox.ActionText == "Turn On" and Opened == false then
Opened = true
prox.ActionText = "Turn Off"
--sound
local Sound = game.ReplicatedStorage.Sounds.Enviromental.LightSwitch
Sound:Play()
--tween
local TS = game.TweenService
local tween = TS:Create(
Door.Main,
TweenInfo.new(.25, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
{CFrame = Door.Main.CFrame * CFrame.Angles(0, 0, math.rad(-90))}
)
tween:Play()
--Lights
local LightsModule = require(script.LightsModule)
LightsModule.lights(Door:FindFirstChild("LightType"))
tween.Completed:Wait()
elseif prox.ActionText == "Turn Off" and Opened == true then
local Sound = game.ReplicatedStorage.Sounds.Enviromental.LightSwitch
Sound:Play()
--tween
local TS = game.TweenService
local tween = TS:Create(
Door.Main,
TweenInfo.new(.25, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
{CFrame = Door.Main.CFrame * CFrame.Angles(0, 0, math.rad(90))}
)
tween:Play()
--Lights
local LightsModule = require(script.LightsModule)
LightsModule.lights(Door:FindFirstChild("LightType"))
tween.Completed:Wait()
--prox
Opened = false
prox.ActionText = "Turn On"
end
end
return module
Module for Lights:
local module = {}
--functions
function module.lights (lightType)
print(lightType.Value)
task.spawn(function()
local Lights = script.Parent.Parent.Parent.Parent.Parent
for _, l in pairs(Lights:GetDescendants()) do
if l:IsA("SpotLight") then
if l.Parent.Name == lightType.Value then
if l.Enabled == false then
l.Enabled = true
elseif l.Enabled == true then
l.Enabled = false
end
end
end
end
end)
end
return module