Detecting problem with textbox

I’m currently making my own admin gui because I want to improve. But I ran into an issue. I have textboxes set up so if I type a player’s name inside it would give the player 1 money for example, but the problem is when I set the player variable to the textbox’s text it just prints the text. It’s not detecting the player’s name it detects the text inside the textbox because i set it to a text. My scripting knowledge doesn’t go that far so I have no idea how to actually get the player’s name with a textbox. Help is appreciated!

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local numberbox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.NumberBox.Text
	local valuebox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.ValueBox.Text
	local playerbox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.PlayerBox.Text
	player = playerbox
	print(player)
	player.Stats.Money.Value = 1
end)

You’re trying to index a string (Stats) with a string (player), hence why your script isn’t working. Instead, use :FindFirstChild(playerbox) on the Players service to check if the typed player exists, and if it does, change the player variable to the actual player instance:

local players = game:GetService("Players")
script.Parent.MouseButton1Click:Connect(function()
	local player = players.LocalPlayer
	local numberbox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.NumberBox.Text
	local valuebox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.ValueBox.Text
	local playerbox = player.PlayerGui.DeveloperMenu.MainFrame.ValueSetter.PlayerBox.Text
	if players:FindFirstChild(playerbox) then
		player = players:FindFirstChild(playerbox)
		print(player)
		player.Stats.Money.Value = 1
	end
end)
2 Likes

Yeah I understand now. I hadn’t had to use FindFirstChild before, so I was unaware of its existence. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.