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

Can you guys help me with a donating stats feature?

Okay so, I was working on a donating stats gui, i added the text boxes where you can enter the player's name that you want to donate to, your player name, and the amount you want to donate to the player, i also added a button that lets you donate below all the text boxes. And then when i finished working on the donate button, it just didn't show any errors and didn't even work

Donate button code:

function Donate()
		local amount = script.Parent.Parent.Amount.Text
		local plrName = script.Parent.Parent.Player.Text
		local plr = game.Players:FindFirstChild(plrName)
		local mplrName = script.Parent.Parent.MainPlayer.Text
		local mplr = game.Players:FindFirstChild(mplrName)
		
		if plr and mplr then
			local s1 = plr.leaderstats.Silks
			local s2 = mplr.leaderstats.Silks
			if s2.Value >= amount then
				s1.Value = s1.Value + amount
				s2.Value = s2.Value - amount
			end
		end
end

script.Parent.MouseButton1Click:Connect(Donate)

Explorer: https://pasteboard.co/K8eWQU1.png

Gui: http://pasteboard.co/K8eXD4i.png

1 answer

✓ Accepted answer

actually, you can make a server script and a local script, first make a remote event, name it Donate then put it in replicated storage then do this for the local script:

script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Donate:FireServer(script.Parent.Parent.Amount.Text, script.Parent.Parent.Player.Text, script.Parent.Parent.MainPlayer.Text)
end)

and for the server script: this

game.ReplicatedStorage.Donate.OnServerEvent:Connect(function(plr, amount, plrtarget, plrmain)
	if game.Players:FindFirstChild(plrtarget) and game.Players:FindFirstChild(plrmain) then
		game.Players:FindFirstChild(plrtarget).leaderstats.Silk.Value = game.Players:FindFirstChild(plrtarget).leaderstats.Silk.Value + amount
		game.Players:FindFirstChild(plrmain).leaderstats.Silk.Value = game.Players:FindFirstChild(plrmain).leaderstats.Silk.Value - amount
		
	end
end)
script.Parent.MouseButton1Click:Connect(Donate)

2 comments

0

i tried it but it didn't work, i even tried to tweak it a lil bit and it still didn't work. it also didn't display any messages in the output

0

sorry for the late response but it worked

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