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)
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.
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)
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)