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

Why isn't the Lighting changing after the player touches a part?

Asked by 4 years ago

Alright, so let me explain this script first, so the script is suppose to change the two Lighting Properties after the player touches the brick and the lighting is not suppose to change after the player leaves the touched area but it's not working for some reason. Any help would be appreciated

The errors in Output:

lighting1 is not a valid member of Humanoid lighting2 is not a valid member of Humanoid

the script:

function onTouched(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    local lighting1 = game.Lighting.FogEnd
    local lighting2 = game.Lighting.FogStart
    if (h ~=nil) then
      h.lighting1 = 40
      h.ligthing2 = 12
    end
 end

script.Parent.Touched:connect(onTouched)
0
I editted my post to include a working script Azure_Kite 885 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Here you go, use this:

local function onTouched(part)
    local h =part.Parent:FindFirstChild("Humanoid")
    local lighting =game.Lighting
    if h then
        lighting.FogEnd =40
        lighting.FogStart =12
    end
end
script.Parent.Touched:connect(onTouched)

You may want to take some time to look up a wiki page about how exactly variables work. The errors you made where very basic, but knowing how to use them properly will be a huge benefit in the future.

0
Alright, I'll test this out in Studio soon and I'll accept it if it works Simpletton 82 — 4y
0
Bonus: You can change game.Lighting from a local script in a player to make local lighting which can work for things like "blinded" effect asgm 109 — 4y
0
This actually worked and I'm using your tip on learning more about variables on the roblox wiki page. Your answer certainly was at least better than the first one. c: Simpletton 82 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Aight so


local lighting1 = game.Lighting.FogEnd local lighting2 = game.Lighting.FogStart

First these 2 line of codes only take the "Value" of FogEnd and FogStart property and put it inside the variables

example : Lets just say currently the FogEnd value is "500"

local lighting1 = game.Lighting.FogEnd
--Above line would be the same as the line below
local lighting1 = 500
--It doesnt make a shortcut, it just assign the value to the variable

Ok so next :

    if (h ~=nil) then
      h.lighting1 = 40
      h.ligthing2 = 12
    end

Soo what exactly you trying to achieve here? First, you can't just use variable as child to an object, thats not how "." works You are trying to find "lighting1" inside a humanoid? but why

what you are doing here is : 1. Check if the Parent of the Part that is touching have a humanoid

(btw, if h then, would have been fine)

  1. Then you tried to use a variable as if its a child of an object and assign value to them

Script Fix :

local light = game.Lighting
script.Parent.Touched:Connect(function(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid then
        light.FogEnd = 40
        light.FogStart = 12
        script.Disabled = true  -- The script seems to be 1 time use only, i suggest disabling it after its done.
    end
end)
0
ok how can I fix my script then? Simpletton 82 — 4y
0
post a fix for my script pls Simpletton 82 — 4y

Answer this question