Money donations won't work properly

So I have a keybind for the moneydonator, and everytime the money is created it would duplicate a donation or the money from serverstorage and parent it to workspace and move it to the players torso. The issue is I’ve tried everything but it wont properly change the value of the donation ammount. To make matters worst, it has no errors. So what happens is a player enters an amount of money they want to donate and it fires the server the amount and the server duplicates it and changes it to the amount.

The GUI code:

local cashamt = script.Parent.Parent.Parent["t-64md"].cashamt
script.Parent.MouseButton1Click:Connect(function()
	if cashamt.Text then
		print(script.Parent.Parent.cashamt.Text)
	game.ReplicatedStorage.SpawnDono:FireServer(script.Parent.Parent.cashamt.Text)
	else
		print("not valid format.")
	end
end)
cashamt.FocusLost:connect(function(enterPressed)
	if enterPressed then
		print(script.Parent.Parent.cashamt.Text)
	game.ReplicatedStorage.SpawnDono:FireServer(script.Parent.Parent.cashamt.Text)
	else
		print("not valid format.")
	end
	end)

ServerCode (listens for the fire from the GUI)

local donate = game.ReplicatedStorage.SpawnDono

--sc
donate.OnServerEvent:Connect(function(player,amount)
	local t = game.Workspace:FindFirstChild(player.Name)
	local m = t.HumanoidRootPart.Position
	local a = game.ServerStorage.donation
    local dupe = a:Clone()
   a.price.Value = amount
    dupe.Name = amount.."$"
dupe.Parent = game.Workspace.Donations
dupe.Head.Position = m
end)

Donation handler ( listens for the fire from the Keybind GUI and gives the money. )

game.ReplicatedStorage.Dono.OnServerEvent:Connect(function(player,dono,amount)
			local t = game.Workspace.Donations:FindFirstChild(dono)
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + amount
		t:Destroy()
end)

If anyone can find a solution, this would be greatly appreciated!

1 Like

Amount is a string value so when your receiving it first take out the dollar sign and then convert the string to number.
First to remove the dollar sign from the amount string u can use the gsub() function like this:

Amount = Amount:gsub('%$','') -- This will remove any dollar signs from the amount string

After you can then convert amount to a number value by:

Amount = tonumber(Amount) --converting the string to numbers

remember you must convert amount tonumber format before you fire the event on the client and prompt the donation.

Still not working.
Added it to the GUI ;

script.Parent.MouseButton1Click:Connect(function()
	if cashamt.Text then
		print(script.Parent.Parent.cashamt.Text)
		local Amount = script.Parent.Parent.cashamt.Text:gsub('%$','') -- This will remove any dollar signs from the amount string
		print(Amount)
	game.ReplicatedStorage.AdminHax.SpawnDono:FireServer(Amount)
	else
		print("not valid format.")
	end
end)
cashamt.FocusLost:connect(function(enterPressed)
	if enterPressed then
				print(script.Parent.Parent.cashamt.Text)
		local Amount = script.Parent.Parent.cashamt.Text:gsub('%$','') -- This will remove any dollar signs from the amount string
		print(Amount)
	game.ReplicatedStorage.AdminHax.SpawnDono:FireServer(Amount)
	else
	end
	end)

And added this to the keybind GUI


	
local UIS = game:GetService("UserInputService") -- Service used to get the key pressed by a player

UIS.InputBegan:connect(function(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the player uses a Keyboard
		if input.KeyCode == Enum.KeyCode.E then -- Checks if the player pressed the "E" key
					for i,v in pairs(game.Workspace.Donations:GetChildren()) do 
					local mag = (v.Head.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
					if mag <= 3.5 then -- If the magnitude is less than or equal to 10 studs then
						--Effect XD
						for i = 1,0.6,-0.05 do
							wait()
							script.Parent.ImageColor3 = Color3.new(0, 0, 0)
						end
						wait()
						for i = 0.6,1,0.05 do
							wait()
							script.Parent.ImageColor3 = Color3.new(255, 255, 255)
						end
						--This effect is like when you pressed a button it will darken.
						local Amount = tonumber(v.price.Value) --converting the string to numbers , where I added it
						game.ReplicatedStorage.Dono:FireServer(v.Name,Amount)
					end
				end
			end
		end
	end)

while wait() do
	script.Parent.Visible = false -- Makes it invisible on screen
	for i,v in pairs(game.Workspace.Donations:GetChildren()) do 
		local mag = (v.Head.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
		if mag  <= 3.5 then -- If the magnitude is less than or equal to 10 studs then
			local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(v.Head.Position) -- The position of the NPC's Torso to 2d
			script.Parent.Visible = true
			script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
			script.Parent.txt.Text = "E to collect  $"..v.Name -- Refreshes the text and puts the name of the npc
		end
	end
	end
	```

image
Format of how the donation money thing is set up. Put that there incase it would be help!

1 Like

does donations have any children

Donations doesn’t. It is in serverstorage.

Still no solution. Here are all the scripts;

GUI that you enter the amount in the textbox and press a button.

script.Parent.MouseButton1Click:Connect(function()
	if cashamt.Text then
		print(script.Parent.Parent.cashamt.Text)
		local Amount = script.Parent.Parent.cashamt.Text:gsub('%$','') -- This will remove any dollar signs from the amount string
		print(Amount)
	game.ReplicatedStorage.SpawnDono:FireServer(Amount)
	else
		print("not valid format.")
	end
end)
cashamt.FocusLost:connect(function(enterPressed)
	if enterPressed then
				print(script.Parent.Parent.cashamt.Text)
		local Amount = script.Parent.Parent.cashamt.Text:gsub('%$','') -- This will remove any dollar signs from the amount string
		print(Amount)
	game.ReplicatedStorage.SpawnDono:FireServer(Amount)
	else
	end
	end)

The script that responds to the fire from the GUI.

donate.OnServerEvent:Connect(function(player,amount)
	local t = game.Workspace:FindFirstChild(player.Name)
	local m = t.HumanoidRootPart.Position
	local a = game.ServerStorage.donation
    local dupe = a:Clone()
   a.price.Value = amount
    dupe.Name = amount.."$"
dupe.Parent = game.Workspace.Donations
dupe.Head.Position = m
end)

The keybind that shows up on the money drop

local UIS = game:GetService("UserInputService") -- Service used to get the key pressed by a player

UIS.InputBegan:connect(function(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then 
		if input.KeyCode == Enum.KeyCode.E then 
					for i,v in pairs(game.Workspace.Donations:GetChildren()) do 
					local mag = (v.Head.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude 
					if mag <= 3.5 then 
						for i = 1,0.6,-0.05 do
							wait()
							script.Parent.ImageColor3 = Color3.new(0, 0, 0)
						end
						wait()
						for i = 0.6,1,0.05 do
							wait()
							script.Parent.ImageColor3 = Color3.new(255, 255, 255)
						end
		
						local Amount = tonumber(v.price.Value) --converting the string to numbers
						game.ReplicatedStorage.Dono:FireServer(v.Name,Amount)
					end
				end
			end
		end
	end)

while wait() do
	script.Parent.Visible = false 
	for i,v in pairs(game.Workspace.Donations:GetChildren()) do 
		local mag = (v.Head.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude 
		if mag  <= 3.5 then 
			local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(v.Head.Position)
			script.Parent.Visible = true
			script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
			script.Parent.txt.Text = "E to collect  $"..v.Name 
		end
	end
	end
	```
--When the keybind fires the server, this script responds to it.
game.ReplicatedStorage.Dono.OnServerEvent:Connect(function(player,dono,amount)
			local t = game.Workspace.Donations:FindFirstChild(dono)
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + amount
		t:Destroy()
end)
1 Like

For the keybind to pickup money it dosent seem liek your adding value
i tryed something similar

local inputservice = game:GetService("UserInputService")

inputservice.InputBegan:connect(function(i,g)
	if i.UserInputType == Enum.UserInputType.Keyboard then
		if i.KeyCode == Enum.KeyCode.E then
			for _,Door in pairs(workspace.Shops:GetChildren()) do
				local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
				if Mag <= Door.Range.Value then
					Door.Event:FireServer()
					break
				end
			end
		end
	end
end)


while true do
	script.Parent.ImageLabel.Visible = false
	for _,Door in pairs(workspace.Shops:GetChildren()) do
		local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
		if Mag <= Door.Range.Value then
			local D3ToD2 = workspace.CurrentCamera:WorldToScreenPoint(Door.Center.Position)
			script.Parent.ImageLabel.Visible = true
			script.Parent.ImageLabel.Position = UDim2.new(0,D3ToD2.X,0,D3ToD2.Y,0) 
				if script.Parent.ImageLabel.Position == UDim2.new(0,D3ToD2.X,0,D3ToD2.Y,0) then
				CurrentPlayer.leaderstats.Cash.Value = CurrentPlayer.leaderstats.Cash.Value + 50
			break
		end
	end
	wait()
end

Hoped this Helped!