Money reset script not working

So I currently am trying to test a cash reset script, from a serverside script. So what happens is there is a serverside script in a gui that listens for a MouseButton1Click. This GUI is in ServerStorage and is duplicated into the player GUI if they are an admin.
Here is the section of code that isn’t working ( for cash/Money reset )

local p = script.Parent --the GUI
local player = p.Parent.Parent --the admin
local reset = script.Parent["t-64md"]['remove:cash'] --the button
local plr = script.Parent["t-64md"].plr --the text box for player name
--remove cash
reset.MouseButton1Click:Connect(function()
	local a = game.Players 
	local r = a:FindFirstChild(plr.Text) --finds the player to reset cash in players
	r.Money = 0 --makes their money 0
end)

So that’s the area of the script where it resets the cash, if anyone could help get this to work it would mean a lot. Thanks!

Edit: The error is;

You forgot to do this:

r.Money.Value = 0

I’m so stupid, sorry. I just woke up and my brain isn’t acting right. I’ll see if that fixes it!

Still the same error;

Players.Kensizo.PlayerGui.AdminHax.MasterControll:16: attempt to index local 'r' (a nil value)
reset.MouseButton1Click:Connect(function()
	local a = game.Players
	local r = a:FindFirstChild(plr.Text) --finds the player to reset cash in players
	if r then
		r.Money.Value = 0 --makes their money 0
	else
		plr.Text = "Invalid"
	end
end)

makes the text invalid every time.

Can you include an image of the GUI in the explorer. Please show all descendants of the GUI.

Did you type out the name correctly? It is case sensitive if you didn’t know.

I did type out the name correctly. Here is a video of the GUI.

Can you tell me what the output is for:

print(plr.Text)

I want to confirm something.
(Put it in the click event).

Try this:

reset.MouseButton1Click:Connect(function()
	local a = game.Players
	local r1 = plr.Text
	for _,Player in pairs(game.Players:GetPlayers()) do
		if string.match(string.lower(string.sub(Player.Name, 1, #r1)), string.lower(r1)) then
			r1 = Player.Name
			break
		end
	end
	local r2 = a:FindFirstChild(r1)
	if r2 then
		r2.Money.Value = 0 --makes their money 0
	else
		plr.Text = "Invalid"
	end
end)
1 Like

Thanks bud! It works. I really appreciate it.

1 Like