Hello,
I’m trying to create a script which changes the ambient lighting based on which zone you are in (part located in the workspace). I’ve gotten everything to work properly but the lighting changes on the server side for all players.
I’ve been trying to use remote events but I’m a little confused on how to keep it on the client side.
Script in StarterCharacterScripts
Lighting = game:GetService('Lighting')
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local City = false
local County = false
game.Workspace.GameNetwork.Zones.City.Touched:Connect(function(partTouched)
if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
City = true
local player = game.Players:FindFirstChild(partTouched.Parent.Name)
local playerGui = player:FindFirstChild("PlayerGui")
local Frame = playerGui:WaitForChild("Main"):WaitForChild("LocationFrame")
local Accent = Frame:WaitForChild("Accent")
local Welcome = Frame:WaitForChild("WelcomeLabel")
local Location = Frame:WaitForChild("LocationName")
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.In)
Location.Text = "City Of Cambridge"
local LocationTween = TweenService:Create(Location, TweenInfo, {TextTransparency = 0})
local WelcomeTween = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 0})
local AccentTween = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 0})
LocationTween:Play()
WelcomeTween:Play()
AccentTween:Play()
task.wait(2)
local LocationTweenOut = TweenService:Create(Location, TweenInfo, {TextTransparency = 1})
local WelcomeTweenOut = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 1})
local AccentTweenOut = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 1})
LocationTweenOut:Play()
WelcomeTweenOut:Play()
AccentTweenOut:Play()
end
end)
game.Workspace.GameNetwork.Zones.City.TouchEnded:Connect(function(partTouched)
if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
City = false
end
end)
game.Workspace.GameNetwork.Zones.County.Touched:Connect(function(partTouched)
if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
County = true
local player = game.Players:FindFirstChild(partTouched.Parent.Name)
local playerGui = player:FindFirstChild("PlayerGui")
local Frame = playerGui:WaitForChild("Main"):WaitForChild("LocationFrame")
local Accent = Frame:WaitForChild("Accent")
local Welcome = Frame:WaitForChild("WelcomeLabel")
local Location = Frame:WaitForChild("LocationName")
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.In)
Location.Text = "Wasaga Beach"
local LocationTween = TweenService:Create(Location, TweenInfo, {TextTransparency = 0})
local WelcomeTween = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 0})
local AccentTween = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 0})
LocationTween:Play()
WelcomeTween:Play()
AccentTween:Play()
task.wait(2)
local LocationTweenOut = TweenService:Create(Location, TweenInfo, {TextTransparency = 1})
local WelcomeTweenOut = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 1})
local AccentTweenOut = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 1})
LocationTweenOut:Play()
WelcomeTweenOut:Play()
AccentTweenOut:Play()
end
end)
game.Workspace.GameNetwork.Zones.County.TouchEnded:Connect(function(partTouched)
if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
County = false
end
end)
while true do
wait()
if City == true then
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local Brightinfo = TweenInfo.new(1.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local Night = false
local Day = false
if Lighting.ClockTime >= 17 or Lighting.ClockTime < 6 then
Night = true
else
Day = true
end
if Night == true then
local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 1})
BrightTween:Play()
BrightTween.Completed:Wait()
local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(52,52,52)})
BrightTween:Play()
BrightTween.Completed:Wait()
elseif Day == true then
local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 2})
BrightTween:Play()
BrightTween.Completed:Wait()
local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(71, 71, 71)})
BrightTween:Play()
BrightTween.Completed:Wait()
end
end
if County == true then
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local Brightinfo = TweenInfo.new(1.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local Night = false
local Day = false
if Lighting.ClockTime >= 17 or Lighting.ClockTime < 6 then
Night = true
else
Day = true
end
if Night == true then
local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 1})
BrightTween:Play()
BrightTween.Completed:Wait()
local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(32,32,32)})
BrightTween:Play()
BrightTween.Completed:Wait()
elseif Day == true then
local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 2})
BrightTween:Play()
BrightTween.Completed:Wait()
local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(78, 78, 78)})
BrightTween:Play()
BrightTween.Completed:Wait()
end
end
end
Any help would be greatly appreciated.