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 5 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:

01function onTouched(part)
02    local h = part.Parent:FindFirstChild("Humanoid")
03    local lighting1 = game.Lighting.FogEnd
04    local lighting2 = game.Lighting.FogStart
05    if (h ~=nil) then
06      h.lighting1 = 40
07      h.ligthing2 = 12
08    end
09 end
10 
11script.Parent.Touched:connect(onTouched)
0
I editted my post to include a working script Azure_Kite 885 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

Here you go, use this:

1local 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
8end
9script.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 — 5y
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 — 5y
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 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Aight so

1local lighting1 = game.Lighting.FogEnd
2local 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"

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

Ok so next :

1if (h ~=nil) then
2  h.lighting1 = 40
3  h.ligthing2 = 12
4end

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 :

1local light = game.Lighting
2script.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
9end)
0
ok how can I fix my script then? Simpletton 82 — 5y
0
post a fix for my script pls Simpletton 82 — 5y

Answer this question