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

Why won't this textbutton give the selected player gold when clicked?

local plrname = script.Parent.Parent.TextBox.Text

script.Parent.MouseButton1Click:Connect(function()
	for i,Player in pairs(game.Players:GetPlayers()) do
		if Player.Name == plrname then
			Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + 10000
		end
	end
end)

This is my script for part of my custom admin panel. This button is supposed to give whatever player typed into the textbox 10,000 Gold, but it doesn't work. If you're wondering why I decided to use an i, v in pairs loop, it's because I don't want the script to break if it can't find the player. I'm not sure why it's not working, so if anyone knows, help would be greatly appreciated. There are no errors in the output, either, as far as I can tell. Help appreciated, thanks.

2 comments

0

GUIs are Localscripts.

0

you can't do this from a localscript, you should use RemoteEvents. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

1 answer

try using :match() :

local plrname = script.Parent.Parent.TextBox.Text

script.Parent.MouseButton1Down:Connect(function()
    for i,Player in pairs(game.Players:GetPlayers()) do
        if Player:lower():match(plrname:lower()) then
            Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + 10000
        end
    end
end)

1 comment

0

Nope, still not working. Should this be in a LocalScript?

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