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

Trying to do a donation gui but it prompts up with an error?

Hi, I am trying to do a donation gui. When I enter the player's name and amount into the textboxes it will prompt up with this error in the console:

"12:29:54.370 - Players.iiLevelMaker.PlayerGui.DonationGUI.Frame.Send.LocalScript:10: attempt to compare string with userdata."

It's on a local script and the money is called "Money" inside of the leaderstats of course.

LocalScript:

local player = game.Players.LocalPlayer

script.Parent.Parent.Username.Changed:connect(function()
	if script.Parent.Parent.Username.Text ~= "Enter Player's Name" then -- Checks so the input of the username is not "Enter Player's Name".
		script.Parent.Text = "Donate to " .. script.Parent.Parent.Username.Text -- Changes the button's text to "Donate to [PLAYERNAME]"
	end
end)

script.Parent.MouseButton1Click:connect(function()
	if player.leaderstats.Money >= script.Parent.Parent.Amount.Text then -- Checks if the person donating has the money.
		if game.Players:FindFirstChild(script.Parent.Parent.Username.Text) then -- Checks if the person who he/she is donating to is online/in-game.
			game.Players:FindFirstChild(script.Parent.Parent.Username.Text).leaderstats.Money = game.Players:FindFirstChild(script.Parent.Parent.Username.Text).leaderstats.Money + tonumber(script.Parent.Parent.Amount.Text) --Adds the amount of money donated to the targets player
		else
			script.Parent.Text = "Player not found." -- Will prompt if the player is not in-game
			wait(3)
			script.Parent.Text = "Donate to ".. script.Parent.Parent.Username.Text
		end
	else
		script.Parent.Text = "Not enough money." -- Will prompt if the player has not enough money
		wait(3)
		script.Parent.Text = "Donate to ".. script.Parent.Parent.Username.Text
	end
end)

GUI Layout: http://prntscr.com/i9j3rl

1 answer

Try using :WaitForChild("Money") instead of directly indexing stuff.

Example: Instead of: local money = player.leaderstats.Money

Use: local money = player:WaitForChild("leaderstats"):WaitForChild("Money")

PS: If the console gives you a warning for 'infinite ammount bla bla bla', simply add another argument [like this: :WaitForChild("Money", 1)].

1 comment

0

That's not the problem, it always work's with that, the problem is that I "Compare string with userdata". And I do not understand it.

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