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:
01 | function onTouched(part) |
02 | local h = part.Parent:FindFirstChild( "Humanoid" ) |
03 | local lighting 1 = game.Lighting.FogEnd |
04 | local lighting 2 = game.Lighting.FogStart |
05 | if (h ~ = nil ) then |
06 | h.lighting 1 = 40 |
07 | h.ligthing 2 = 12 |
08 | end |
09 | end |
10 |
11 | script.Parent.Touched:connect(onTouched) |
Here you go, use this:
1 | local function onTouched(part) |
2 | local h = part.Parent:FindFirstChild( "Humanoid" ) |
3 | local lighting = game.Lighting |
4 | if h then |
5 | lighting.FogEnd = 40 |
6 | lighting.FogStart = 12 |
7 | end |
8 | end |
9 | 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.
Aight so
1 | local lighting 1 = game.Lighting.FogEnd |
2 | local lighting 2 = 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"
1 | local lighting 1 = game.Lighting.FogEnd |
2 | --Above line would be the same as the line below |
3 | local lighting 1 = 500 |
4 | --It doesnt make a shortcut, it just assign the value to the variable |
Ok so next :
1 | if (h ~ = nil ) then |
2 | h.lighting 1 = 40 |
3 | h.ligthing 2 = 12 |
4 | 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)
Script Fix :
1 | local light = game.Lighting |
2 | script.Parent.Touched:Connect( function (part) |
3 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
4 | if humanoid then |
5 | light.FogEnd = 40 |
6 | light.FogStart = 12 |
7 | script.Disabled = true -- The script seems to be 1 time use only, i suggest disabling it after its done. |
8 | end |
9 | end ) |