I want to create a working light, but I am being greeted with attempt to index nil with ′LightFL1′
Here is the code:
task.wait()
local player=game.Players.LocalPlayer
local mouse=player:GetMouse()
local Body = script.Parent.Parent.Parent:FindFirstChild("Body")
mouse.KeyDown:connect(function(key)
if key=="l" then
Body.LightFL1.Material = Enum.Material.Neon
print("you")
end
end)
That error means that Body
in your code is nil. You need to make sure that variable holds the instance you need.
1 Like
Could you please explain more?
Im only an amateur in coding…
I also tried changing :FindFirstChild()
to :WaitForChild()
, but I got greeted by this warning:
Infinite yield possible on ‘Players.Rekotora3349:WaitForChild(“Body”)’
From this new error I can deduce that the reason it’s not finding the Body
is because it’s looking for it in the wrong place. It’s looking for Body
in the Player
object (which really isn’t where it is located). I don’t know where this “Body
” object is though, so can you show me where it’s supposed to be?
Sure.
Here is the placement before playing.
Here is the placement after playing.
(Note: I am trying to execute this code in A-Chassis.)
try setting body to
local Body = script:FindFirstAncestorWhichIsA('Model'):WaitForChild('Body')
As soon as I sat there, I noticed this in output:
thats weird.
is there any invisible characters/spaces in body?
if there isnt i would recommend removing the task.waits() and running
print(script:GetFullName())
to see if the script is being moved somewhere else even if its unlikely
The script is under the UI Interface that’s parented to your PlayerGui
. You need to have a reference to the A-Chassis model that’s in the Workspace, try using workspace["A-Chassis 6.81T by Novena"]
and then getting the Body
object.
There will be more chassis… Wouldn′t it break?
well since its under a module script the module script itself will likely have a reference to the body so try and look for that.
Hmm… The interface seems to have a Car ObjectValue
, which you can use to get it instead.
The local script doesn’t have access to the module, since it’s in the UI that’s being parented to your PlayerGui
. The module is in the chassis itself.
What do you mean by object value?
Body = script:FindFirstAncestorWhichIsA('ScreenGui'):WaitForChild('Car')['Value']:WaitForChild('Body')
according to mr car expert bilon
1 Like
This thing. I’m not sure, but it could be an ObjectValue
which you can get the .Value
property of and get the Chassis model.
i just changed the script to get the body instead of just the model of the car
1 Like