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

ROBLOX Gui help?

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.

2 answers

✓ Accepted answer

There are 2 problems with your script.

  1. You are not checking if the player exists. plyr = game.Players:findFirstChild(""..pname)

  2. You are not updating the pname and plyr variable. So if it was empty when the script ran, it will stay empty.

Solution:

  1. We will use an if condition to check if the plyr does exist if plyr then

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

1 comment

0

That did not work for me, it still gives me an error. Thank you for posting though.

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