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

Attempting to local index '' (nil value)?

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.

2 comments

0

Is script.Value an ObjectValue or a StringValue?

0

ObjectValue

1 answer

✓ Accepted answer

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.

2 comments

0

Thanks! Worked like a charm. I'll make sure to make my code clearer in the future, and thank you for the explanation.

0

Glad I could help.

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