Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Change Lighting On The Client Side?

Asked by
Donut792 216 Moderation Voter
5 years ago

alright so this question seems pretty simple right? well i think im missing something here because in the past i used to just be able to insert a local script and have it change game lighting during a touched event but this has been about a year ago so Roblox has of course changed and now that for some reason doesnt work and so my final approach for solving the issue was doing the simple thing of using remote events so is set up my script Script:

local sound = "rbxassetid://2880683456"
local gui = script:WaitForChild("AreaTitle")
local event = script.Parent.Parent.ChangeLighting
script.Parent.Touched:Connect(function(hit)
    if game.Players:findFirstChild(hit.Parent.Name) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        game.ReplicatedStorage.PlayMusic:FireClient(player,sound)
        local CurrentArea = player:WaitForChild("CurrentArea")
        if CurrentArea.Value ~= "Mystery Cave" then
            CurrentArea.Value = "Mystery Cave"
            event:FireClient(player)
            if player.PlayerGui:FindFirstChild("AreaTitle") == nil then
                local clone = gui:Clone()
                clone.Parent = player.PlayerGui
                clone.Script.Disabled = false
            end
        end
    end
end)

and then i sauteed up my client side script LocalScript:

local l = game.Lighting
script.Parent.Parent.ChangeLighting.OnClientEvent:Connect(function()
    l.Brightness = .1
    l.Ambient = Color3.new(84/255, 15/255, 83/255)
    l.OutdoorAmbient = Color3.new(186/255, 87/255, 206/255)
    l.FogEnd = 550
    l.FogStart = 100
    l.FogColor = Color3.new(104/255, 30/255, 103/255)
    l.ExposureCompensation = .43
end)

and bam before i knew i absolutely no results what so ever (welcome to Roblox) and beforehand i made sure i knew what i was typing and converted it over to server side just to make sure this chef had all his ingredients correct Script:

local l = game.Lighting
script.Parent.Touched:Connect(function(hit)
    if game.Players:findFirstChild(hit.Parent.Name) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        script.Parent.Parent.Entered.Value = true
        l.Brightness = .1
        l.Ambient = Color3.new(84/255, 15/255, 83/255)
        l.OutdoorAmbient = Color3.new(186/255, 87/255, 206/255)
        l.FogEnd = 550
        l.FogStart = 100
        l.FogColor = Color3.new(104/255, 30/255, 103/255)
        l.ExposureCompensation = .43
    end
end)

and then everything worked exactly as it was supposed to just server sided so i know the script i'm writing here is correct, but what is its reasoning to not run? its kinda hard to debug localscripts when Roblox just decides to disable print,warn, and error functions from popping up in the console (unless i'm just on the funky part of town and messed with a game setting somewhere i didn't know about)

1
Roblox doesn't have console disabled for local scripts. One possible reason why your script isn't doing anything is because you have it parented to someone that can't run scripts. Also, I don't think local scripts run when their are parented to ScreenGui's that have Enabled set to false. AbusedCocopuff4 105 — 5y
0
Well, I wouldn't be putting a script like this under any GUI elements... why not just paretnt it to the Player's startup scripts instead? JasonTheOwner 391 — 5y
0
Well, I wouldn't be putting a script like this under any GUI elements... why not just paretnt it to the Player's startup scripts instead? JasonTheOwner 391 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Change one line of code in your original LocalScript to not touch game.Lighting and get it from the Service instead, and you're all set.

local l = game:GetService("Lighting") 

I tested this change to your script above, and it works great! I'm going to use this, also. The reason this works instead of game.Lighting, probably has to do with behavior of Filter Enabled. I tried it your way as well... and it didn't work.

0
ah, thank you, still didnt work for me but ill figure it out in the long run glad that your using my system in your own game though that always makes me happy :) Donut792 216 — 5y
0
i went with an entire different system where i have the local script in StarterGui and and i just make it go off of events now and it works perfectly Donut792 216 — 5y
0
Okay great, glad you got it working. Yeah I tested it by running a function in one of my module scripts, after pressing a GUI button. JasonTheOwner 391 — 5y
Ad

Answer this question