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

ROBLOX Gui help?

Asked by 9 years ago

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

Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
9 years ago

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)
Ad
Log in to vote
-1
Answered by 9 years ago

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.

0
That did not work for me, it still gives me an error. Thank you for posting though. Kiriakashi 20 — 9y

Answer this question