Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempting to local index '' (nil value)?

Asked by 7 years ago
Edited 7 years ago

Basically, I have this script which when the LocalPlayer will hover over a certain object, it will show a BillboardGui, however only to them. I have another brick which will do something else when it has been hovered over.

This is the error:

19:06:31.506 - Players.Player1.PlayerGui.LocalScript:18: attempt to index local 'plr2' (a nil value)
19:06:31.507 - Stack Begin
19:06:31.508 - Script 'Players.Player1.PlayerGui.LocalScript', Line 18
19:06:31.509 - Stack End

And this is the code:

local player = script.Parent.Parent
mouse = game.Players.LocalPlayer:GetMouse()


mouse.Move:connect(function()
if mouse.Target and mouse.Target.Name == "Handle"
    then
        local plr = mouse.Target.Parent.Parent
        print(plr.Name)
        mouse.Target.BillboardGui.Enabled = true
        script.Value.Value = plr
else
    if mouse.Target and mouse.Target.Name == "Part"
        then
        local plr2 = game.Workspace:FindFirstChild(script.Value.Value)
        plr2.ModeratorHat.Handle.BillboardGui.Enabled = false
end
end
end)

It is a localscript so that only the local player can see the BillboardGui. There is also a objectvalue inside the script in order to hold the value of the player who is wearing 'Handle'. I understand that the error is because the script cannot locate where 'plr2' is, however I do not know how to fix it. I want it so that when the player hovers over 'Part', the BillboardGui will disappear (only to them again).

Thanks.

0
Is script.Value an ObjectValue or a StringValue? AstrealDev 728 — 7y
0
ObjectValue toughjohncena1256 57 — 7y

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
7 years ago

FindFirstChild only takes a string as a parameter, and from you saying its an ObjectValue, it will therefore not work. If you have an ObjectValue, and a value for it, you can access the object straight from the value using script.Value.Value. Say if it was a part, I could do script.Value.Value.BrickColor = BrickColor.new("Really red") to change its color to red. I do recommend renaming 'Value' in the future so you don't get confused, and those helping you aren't confused.

0
Thanks! Worked like a charm. I'll make sure to make my code clearer in the future, and thank you for the explanation. toughjohncena1256 57 — 7y
0
Glad I could help. Shawnyg 4330 — 7y
Ad

Answer this question