Cash giver with TextLabel

Im making a script where i can give cash to the players that i choose with a text label but the text labels are not updating and stays empty so i dont know what to do now

image

local SendButton = script.Parent.Parent.Parent.SendButton
local UsernameText = script.Parent
local AmountText = script.Parent.Parent.Parent.Frame2.AmountText

SendButton.MouseButton1Click:Connect(function(plr)
	local playername = tostring(UsernameText.Text)
	local Amount = tostring(AmountText.Text)
	
	print(Amount)
	print(playername)
	
	game.Players:FindFirstChild(playername).leaderstats.Cash += Amount
end)

What is mean by “not updating” is this
image
image

The text does update, the reason you don’t notice it is because you’re checking inside the wrong place, the StarterGui. Every time a player spawns all the UI/scripts from StarterGui are copied(unless a UI has ResetOnSpawn set to false) inside the PlayerGui of said player. By checking the StarterGui you basically check that placeholder not the actual instance of the UI. Instead you need to check inside game -> Players -> player username -> PlayerGui where the UI you see during playtest is.

Your script will still not work tho because it’s fully client sided, meaning that only you will see the leaderstat value change, but everyone else(and the server) wont. Instead if you want this to replicate(and I assume you do) you need to use a remote event. A remote event is an instance that acts as a way to send signals/communicate between client and server. So you send playername and Amount through the remote event, a server script picks it up and then on the server it runs the line game.Players[playername].leaderstats.Cash += Amount. The first argument on the server will be the player that fired the remote(in this case you). I suggest before running any code on the server you perform a check to ensure that a whitelisted user fired the remote, else exploiters will be able to use the remote and give money to people.

1 Like

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