Hi, I’m really tired of this topic and I’ll try to explain the best I can. The following LocalScript is used to detect values of a stringValue and it depends on the stringvalue, it changes the quality of the shadows but it does not detect them or anything, I have other scripts the same but those if it detects them. However, with a normal script if it works or at least in the serverScriptService datastore.
local Lighting = game:GetService("Lighting")
local StringValueShadow = game.Players.LocalPlayer:WaitForChild("Graficos"):WaitForChild("Shadow")
StringValueShadow:GetPropertyChangedSignal("Value"):Connect(function()
if StringValueShadow.Value == "Bajo" then
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
Lighting.GlobalShadows = false
Lighting.ShadowSoftness = 1
item.Shadows = false
item.Brightness = 0.35
print("Sombras en bajo")
end
end
elseif StringValueShadow.Value == "Medio" then
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
Lighting.GlobalShadows = true
Lighting.ShadowSoftness = 0.5
item.Shadows = false
item.Brightness = 0.35
print("Sombras en medio")
end
end
elseif StringValueShadow.Value == "Alto" then
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
Lighting.GlobalShadows = true
Lighting.ShadowSoftness = 0.1
item.Shadows = true
item.Brightness = 0.75
print("Sombras en alto")
end
end
end
return
end)
@Soybeen’s checklist is where your problem lies, as I can confirm the code compiles and functions correctly so long as everything is where it needs to be. One other suggestion I would make on the code aspect would be to move your Lighting changes outside of the loops that change the individual lights, like this:
if StringValueShadow.Value == "Bajo" then
Lighting.GlobalShadows = false
Lighting.ShadowSoftness = 1
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
item.Shadows = false
item.Brightness = 0.35
print("Sombras en bajo")
end
end
elseif StringValueShadow.Value == "Medio" then
Lighting.GlobalShadows = true
Lighting.ShadowSoftness = 0.5
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
item.Shadows = false
item.Brightness = 0.35
print("Sombras en medio")
end
end
elseif StringValueShadow.Value == "Alto" then
Lighting.GlobalShadows = true
Lighting.ShadowSoftness = 0.1
for _, item in ipairs(workspace:GetDescendants()) do
if item:IsA("PointLight") then
item.Shadows = true
item.Brightness = 0.75
print("Sombras en alto")
end
end
end
We could go one step further with this and make a dictionary filled with lighting properties using your special strings as keys.
local lightingProfiles = {
["Bajo"] = {
["PointLight"] = {
["Shadows"] = false,
["Brightness"] = 0.35,
},
["Lighting"] = {
["GlobalShadows"] = false,
["ShadowSoftness"] = 1,
},
},
["Medio"] = {
["PointLight"] = {
["Shadows"] = false,
["Brightness"] = 0.35,
},
["Lighting"] = {
["GlobalShadows"] = true,
["ShadowSoftness"] = 0.35,
},
},
["Alto"] = {
["PointLight"] = {
["Shadows"] = true,
["Brightness"] = 0.75,
},
["Lighting"] = {
["GlobalShadows"] = true,
["ShadowSoftness"] = 0.1,
},
},
}
local Lighting = game:GetService("Lighting")
local stringValue = -- define your stringValue here
stringValue.Changed:connect(function(newValue)
for property,value in next,lightingProfiles[newValue]["Lighting"] do
Lighting[property] = value
end
for _,obj in next,workspace:GetDescendants() do -- it would be better if you compiled all your PointLights into table, to avoid massive iteration through everything in Workspace
if obj:IsA("PointLight") then
for property,value in next,lightingProfiles[newValue]["PointLight"] do
obj[property] = value
end
end
end
end)
I think it should almost be done but in your part of the script I get an error Workspace.NUTRICORP.Graficos: 4: attempt to index nil with 'Lighting’
local RemoteEventShadow = ReplicatedStorage.Graficos:WaitForChild("FireShadowChangeScript")
local function ChangeShadowSingal(newValue)
for property,value in next,lightingProfiles[newValue]["Lighting"] do
Lighting[property] = value
end
for _,obj in next,workspace:GetDescendants() do -- it would be better if you compiled all your PointLights into table, to avoid massive iteration through everything in Workspace
if obj:IsA("PointLight") then
for property,value in next,lightingProfiles[newValue]["PointLight"] do
obj[property] = value
end
end
end
end
RemoteEventShadow.OnClientEvent:Connect(ChangeShadowSingal)
It looks like the value sent along your RemoteEventShadow is not “Bajo”, “Medio”, or “Alto”. It must be one of those three strings in order to properly index the lightingProfiles table.