Ok, so basically I am making a GUI that will distribute a value called "Insignia" I will provide you pictures on where everything is to make your life and my life easier. Link1Link2 and finally, Link3
So the error I get is: 19:11:22.526 - Players.Player.PlayerGui.AdminGui.Background.Distribute.Script:6: attempt to index global 'plyr' (a nil value) 19:11:22.527 - Stack Begin 19:11:22.528 - Script 'Players.Player.PlayerGui.AdminGui.Background.Distribute.Script', Line 6 19:11:22.529 - Stack End
And the script is:
pname = script.Parent.Parent.Player.Text plyr = game.Players:findFirstChild(""..pname) script.Parent.Parent.Distribute.MouseButton1Click:connect(function() if script.Parent.Parent.Parent.InsigniaValue.Value > 0 then plyr.Data.InSig.Value = plyr.Data.InSig.Value + script.Parent.Parent.Parent.InsigniaValue.Value if script.Parent.Parent.Parent.InsigniaValue.Value < 0 then plyr.Data.InSig.Value = plyr.Data.InSig.Value - script.Parent.Parent.Parent.InsigniaValue.Value end end end)
If you could help me, that would be amazing.
There are 2 problems with your script.
You are not checking if the player exists.
plyr = game.Players:findFirstChild(""..pname)
You are not updating the pname and plyr variable. So if it was empty when the script ran, it will stay empty.
Solution:
We will use an if condition to check if the plyr does exist
if plyr then
We will update the pname and plyr variables every time we click the distribute text button.
Code:
script.Parent.Parent.Distribute.MouseButton1Click:connect(function() local pname = script.Parent.Parent.Player.Text local plyr = game.Players:findFirstChild(pname) if plyr then if script.Parent.Parent.Parent.InsigniaValue.Value > 0 then plyr.Data.InSig.Value = plyr.Data.InSig.Value + script.Parent.Parent.Parent.InsigniaValue.Value elseif script.Parent.Parent.Parent.InsigniaValue.Value < 0 then plyr.Data.InSig.Value = plyr.Data.InSig.Value - script.Parent.Parent.Parent.InsigniaValue.Value end end end)
So I looked this over, and I don't understand this line:
plyr = game.Players:findFirstChild(""..pname)
I think it's not finding the player because of the weird thing (""..pname) that you did in the findFirstChild method.
pname is already a string on its own, so all you'd have to put is:
plyr = game.Players:FindFirstChild(pname)
And that should make the script function correctly.