Hey there, I've got a system of a few scripts that aren't working quite as intended. Here's what I'm trying to do:
I am attempting to create a "save point" system in my game, where the player will spawn from if they die. These save points take the form of phone booths. When someone clicks on a phone, they will "save" at that booth and respawn from it thereafter.
The phone booths have flickering blue lights. When a player saves at a booth, I want that booth's lights to turn white for that player only. Additionally, while the player is "calling" from the phone, the light should stop flickering.
Here are images of the relevant objects to the system in the explorer. [1] [2]
Dramatis Personae:
FlickerEnabled: boolean value that should determine whether the lights can flicker.
LightColor: color3 value that determines what color the lights are.
LightFlicker: script containing light flickering functionality
Save: script containing the save process functionality
PhoneColorUpdate: remove event for this
PhoneSelector: localscript containing phone color changing
What I have succeeded in so far is changing the player's spawn location between booths. Previously, stopping the flicker used to work as well, before I started to mess around with the client-side lighting color changing. As of now, the color change does not function no matter what mode I attempt to play the game in, and the light flickering loop runs even when FlickerEnabled is set to false.
I have tried to debug this myself with some helpful printing here and there, and the only conclusion I can reach is that these values do not stay updated and default back to their original values. As no errors actually occur with the scripts it is difficult to say (Every print line is ran the expected # of times, with the exception of the last one in LightFlicker which only prints once, leading me to believe that the boolean just resets back to true)
I have a sneaking suspicion I don't really understand how RemoteEvents work and am trying to use them for the wrong purpose here, but that does not explain why the lights continue to flicker, as this is a serverside change, and was working as intended at some point (not exactly sure what changed, sorry).
Here are the three scripts in full. Thank you for your time, and if you need anything else from me, please ask.
Save:
local clickDetector = script.Parent.ClickDetector
local debounce = false
local phoneSpawn = script.Parent.Parent.SpawnLocation
local phoneSpawnAdj = phoneSpawn.CFrame + Vector3.new(0, 2.5, 0)
local phoneHungParts = {}
local phoneCallingParts = {}
local flickerEnabled = script.Parent.Parent.FlickerEnabled.Value
local phoneColorUpdate = game.ReplicatedStorage:WaitForChild("PhoneColorUpdate")
local phoneBooth = script.Parent.Parent
for _, v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
table.insert(phoneHungParts, v)
end
end
for _, v in pairs(script.Parent.Parent.PhoneCalling:GetChildren()) do
if v:IsA("BasePart") then
table.insert(phoneCallingParts, v)
end
end
local function changePhoneTransparency(phone, trans)
for _, v in pairs(phone) do
v.Transparency = trans
end
end
local function onMouseClick(player)
if debounce == false then
debounce = true
phoneColorUpdate:FireClient(player, phoneBooth)
flickerEnabled = false
print("flickerEnabled is " .. tostring(flickerEnabled))
local character = player.Character
local head = character:FindFirstChild("Head")
--character.HumanoidRootPart.Position = phoneSpawn.Position
--character:MoveTo(phoneSpawn.Position - Vector3.new(0, -1, 0))
character:SetPrimaryPartCFrame((phoneSpawnAdj * CFrame.Angles(0, math.rad(180), 0)))
head.Anchored = true
wait(0.5)
changePhoneTransparency(phoneHungParts, 1)
changePhoneTransparency(phoneCallingParts, 0)
wait(2)
player.RespawnLocation = phoneSpawn
game:GetService('Chat'):Chat(script.Parent.Parent.PhoneCalling.Speaker, "Position " .. "registered.")
wait(2)
changePhoneTransparency(phoneHungParts, 0)
changePhoneTransparency(phoneCallingParts, 1)
head.Anchored = false
flickerEnabled = true
debounce = false
end
end
clickDetector.MouseClick:connect(onMouseClick)
PhoneSelector:
local phoneColorUpdate = game.ReplicatedStorage:WaitForChild("PhoneColorUpdate")
local phoneBoothColors = {}
for _, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("Color3Value") then
table.insert(phoneBoothColors, v)
print("Found a color value")
end
end
local function updatePhoneSpawn(phoneBoothSavingAt)
print("Input received")
for _, v in pairs(phoneBoothColors) do
if v.Parent == phoneBoothSavingAt then
v.Value = Color3.new(255, 255, 255)
print("Changed saved phone booth color")
else
v.Value = Color3.new(0, 255, 255)
print("Changed other phone booth colors")
end
end
end
phoneColorUpdate.OnClientEvent:Connect(updatePhoneSpawn)
LightFlicker
local symbol = script.Parent.PhoneSymbol
local lights = {}
for _, v in pairs(script.Parent:GetChildren()) do
if v.Name == "Light" then
table.insert(lights, v)
end
end
while true do
wait(math.random(0.5, 2))
local flickerEnabled = script.Parent.FlickerEnabled.Value
if flickerEnabled == true then
local lightColor = script.Parent.LightColor.Value
for _, v in pairs(lights) do
local light = v
light.BrickColor = BrickColor.new("Black")
light.Material = Enum.Material.Glass
light.SurfaceLight.Enabled = false
end
symbol.BrickColor = BrickColor.new("Black")
symbol.Material = Enum.Material.Glass
wait(0.1)
for _, v in pairs(lights) do
local light = v
light.Color = lightColor
light.Material = Enum.Material.Neon
light.SurfaceLight.Color = lightColor
light.SurfaceLight.Enabled = true
end
symbol.Color = lightColor
symbol.Material = Enum.Material.Neon
else
print("flickerEnabled is " .. tostring(flickerEnabled))
end
end

3 comments
If your changing them on the client or changing them on the server you gotta turn them off on the server or the client.
Could you explain what you mean?
Someone partially helped me out on this in the Discord. The reason that LightColor wouldn't update for the client was that the server script LightFlicker was reading LightColor from the server's end rather than the client's. I am still lost on why FlickerEnabled won't update, though.