Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

I editted my post to include a working script

2 answers

✓ Accepted answer

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.

3 comments

0

Alright, I'll test this out in Studio soon and I'll accept it if it works

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

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:

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)

2 comments

0

ok how can I fix my script then?

0

post a fix for my script pls

This discussion is preserved as it was. New answers, comments, and votes are closed.