Hello, guys! I’ve been trying to make a money displayer for my Hood Game and I have a problem. But before I say the problem, I want to say that the displayer is done but the problem is another issue.
So, the green one is the money that the player has. Don’t mind the white. The golden one is the money that the player gets or losses.
But the problem is that I want to to make it like it says automatically how much money the player got and how much money the player lost but I don’t want to make it by the way I will describe it. I don’t want to make everytime a script for each money increase or loss. What I mean is that there will be a lot of ways to make money in the game but I want to make it like it says automatically what is the money increase amount or loss amount. Sorry if I make anyone of you confused
I tried searching every youtube tutorial but I couldn’t find anything.
-- Local Player
local plr = game.Players.LocalPlayer
-- Folder That Contains Data
local DataFolder = plr:WaitForChild("DataFolder")
-- Money[Bank/Wallet]
local walletMoney = DataFolder.Money
local bankMoney = DataFolder.BankMoney
-- UI
local WalletMoneyUI = script.Parent.WalletMoney
local BankMoneyUI = script.Parent.BankMoney
-- Functions
local function onWalletMoneyChange()
WalletMoneyUI.Text = "$"..walletMoney.Value
end
local function onBankMoneyChange()
BankMoneyUI.Text = "$"..bankMoney.Value
end
-- Connections
walletMoney.Changed:Connect(onWalletMoneyChange)
bankMoney.Changed:Connect(onBankMoneyChange)
The above script is the script that I have for the displayers.
You can just use a changed event, everytime the value changes you take the difference from the original money and the new money
local OldMoney = Money.Value
Money.Changed:Connect(function(NewMoney)
local Diff = NewMoney - OldMoney
print(Diff) -- This is how much money the player earned
OldMoney = NewMoney
end)
Alternatively you can create a module script and store a funciton to increase money while also updating the UI, and then just have everyone script use that function
How are you planning on changing the values? If you’re changing the value normally, maybe you could attach that function with a RemoteEvent, to give the same value that is changing the players money value. If it doesn’t make sense, check this example:
-- this is just an example
local Players = game:GetService("Players")
local exampleRemote = game.ReplicatedStorage.exampleRemote
BasePart.Touched:Connect(function(whoTouched)
local player = Players:GetPlayerFromCharacter(whoTouched.Parent)
if player then
local moneyValue = player:FindFirstChild("DataFolder").WalletMoney
moneyValue.Value -= 500
exampleRemote:FireClient(player, 500, "taking") --[[these are key values.
the 500 is the amount of money that's in the operation,
and "taking" is another key value of what type of action is being operated.]]
end
end)
Then, in your script, you could add another function to listen for the remote. Using the values that it’s sending out to display the amount that was taken or given.
local exampleRemote = game.ReplicatedStorage.exampleRemote
local AmountTakenOrGiven = script.Parent.Parent.GivenMoney -- i'm assuming this is the UI for displaying how much money is being taken or given
exampleRemote.OnClientEvent:Connect(function(money, transaction)
if transaction == "taking" then
AmountTakenOrGiven.Text = "- $" .. money
elseif transaction == "giving" then
AmountTakenOrGiven.Text = "+ $" .. money
end
end)
The second script is what you’ll add inside of your script for changing the display UI’s.
The first script is just an example for how you’d change the value of a player and sending off the information of the transaction. You can do this with anything, but I just used a part as an example.
But the general gist of it is that, you’ll need to have a remote event and you have to fire the remote inside of a normal script (or else it won’t work) with the things that’s inside of the :FireServer() function.
If you need help on setting up the first script on certain things (like having it fire the server after pressing a UI Button, or having it fire when a player “mugs” another player, or when they get a paycheck, etc.), let me know!
Just letting you know, you can still add people even if they’re not friends with you on roblox. But, I’ll still friend you! I’ll also add you on Discord as well. Look out for a user named “edo”.