I’m using a lighting zone script. it works fine in studio but doesn’t work in-game
I don’t understand what the heck is going on.
script:
print("@")
local player = game.Players.LocalPlayer
local triggers = game.Workspace:WaitForChild("EnvironmentTriggers")
local default1 = triggers:WaitForChild("Default1")
local Settings = script.Parent:WaitForChild("Settings")
local default = script.Parent:WaitForChild("DefaultProperties")
local modify = require(script:WaitForChild("ModifyProperties"))
print("1")
modify.ApplyDefaults() --// Begin by initializing default settings
player.CharacterAdded:Connect(function(character)
modify.ApplyDefaults() --// If value is true, reset lighting on spawn
if Settings:WaitForChild("ApplyDefaultOnSpawn").Value == true then
modify.ApplyDefaults() --// If value is true, reset lighting on spawn
end
print("2")
local root = character:WaitForChild('HumanoidRootPart') --// Compatable with both R15 and R6
print("3")
root.Touched:Connect(function(trigger)
if trigger.Parent == triggers then --// If hit part is a trigger
modify.Update(trigger)
print("4")
end
end)
end)
It’s possible the character is being added before the connection, causing the rest of the script to not run. You should do a check for if the character is already added after the connection, and turn the code inside the connection into a function which can be used in both cases.
local modify = {}
local tweenService = game:GetService("TweenService")
local default = script.Parent.Parent:WaitForChild("DefaultProperties")
function modify.Update(trigger, transitionOverride)
for _,v in pairs(default:GetChildren()) do
if not trigger:FindFirstChild(v.Name) then
v:Clone().Parent = trigger --// If trigger doesn't have default values, give it them
end
end
local tweenInfo = TweenInfo.new(transitionOverride or trigger.TRANSITION.Value) --// The tween info for the transition time, will be reused
for _,value in pairs(trigger:GetChildren()) do
local modifiedProperties = {}
local succ, err = pcall(function()
if value.Name ~= 'TRANSITION' and value.Name ~= 'Atmosphere' then
local goal = {[value.Name] = value.Value}
local tween = tweenService:Create(game.Lighting, tweenInfo, goal)
tween:Play()
table.insert(modifiedProperties, value.Name)
end
end)
if not succ then
warn(err)
end
if value.Name == 'Atmosphere' then
for _,atmospheric in pairs(value:GetChildren()) do
local goal = {[atmospheric.Name] = atmospheric.Value}
local tween = tweenService:Create(game.Lighting.Atmosphere, tweenInfo, goal)
tween:Play()
end
end
end
end
function modify.ApplyDefaults()
modify.Update(default, 0)
end
return modify
I can only suggest adding some print statements to you module:
local modify = {}
local tweenService = game:GetService("TweenService")
local default = script.Parent.Parent:WaitForChild("DefaultProperties")
function modify.Update(trigger, transitionOverride)
print("trigger, transitionOverride =", trigger, transitionOverride)
for _,v in pairs(default:GetChildren()) do
print("v =", v)
if not trigger:FindFirstChild(v.Name) then
print("trigger not found", v.Name)
v:Clone().Parent = trigger --// If trigger doesn't have default values, give it them
end
end
local tweenInfo = TweenInfo.new(transitionOverride or trigger.TRANSITION.Value) --// The tween info for the transition time, will be reused
for _,value in pairs(trigger:GetChildren()) do
local modifiedProperties = {}
local succ, err = pcall(function()
if value.Name ~= 'TRANSITION' and value.Name ~= 'Atmosphere' then
local goal = {[value.Name] = value.Value}
local tween = tweenService:Create(game.Lighting, tweenInfo, goal)
tween:Play()
table.insert(modifiedProperties, value.Name)
print("success")
end
end)
if not succ then
warn(err)
end
if value.Name == 'Atmosphere' then
print("Atmosphere")
for _,atmospheric in pairs(value:GetChildren()) do
local goal = {[atmospheric.Name] = atmospheric.Value}
local tween = tweenService:Create(game.Lighting.Atmosphere, tweenInfo, goal)
print("goal =", goal)
tween:Play()
end
end
end
end
function modify.ApplyDefaults()
modify.Update(default, 0)
end
return modify