Introduction
Making a GUI currency giver is a pretty simple task to complete and might be helpful to help boost something of yours quickly.
I first wanted to make something like this when I saw a video created by ZephPlayz with Roblox, when Zeph came into the game he found a R$ GUI giver that “gave” him Robux (I Played ROBLOX'S Free Robux Game.. - YouTube (10:16-11:25)). I thought to myself, well what if I made one to give currency to someone in my game? I started constructing and with a little help from dev forum I was able to complete this project and share it with everyone.
Please note this is not a very necessary thing to know when programming a game, but it is pretty fun to play with and good to learn from.
Set Up
The first thing you want to do when setting up this GUI is obviously create one in StarterGui, and build a model/part to open up the currency giver. In the model/part you made, add a Click Detector and (Server)Script. In the script add a remote event to send to the client for when the click detector has been clicked.
local debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if debounce == false then -- add a debounce, so it can't be clicked so many times
debounce = true
game.ReplicatedStorage.FatbuxG:FireClient(plr) --FatbuxG is the name of my remote event
wait(16) -- we add FireClient(plr) to make sure it sends to only the person who clicked it
debounce = false
end
end)
After some time of decorating and scripting this, I ended up coming with this example:
Now we need to make it so the GUI will appear when it receives the remote event. In a local script I added this:
game.ReplicatedStorage.FatbuxG.OnClientEvent:Connect(function()
script.Parent.Parent.Visible = true -- make sure to add all of your things in the Frame and set them to either visible or not
script.Parent.Parent.giving.Visible = false
script.Parent.Visible = true
script.Parent.Parent.TextBox2.Visible = true
script.Parent.Parent.TextBox.Visible = true
script.Parent.Parent.text.Visible = true
script.Parent.Parent.enter.Visible = true
end)
script.Parent.MouseButton1Click:Connect(function() -- function to close GUI if denied
script.Parent.Parent.Visible = false
end)
Creating The GUI Function
Now that everything has been setup, we can start to create the actual function of the GUI. Let’s first start by making it so players can only type numbered strings into the amount textbox (the amount of currency someone types in). Insert a local script into your amount textbox. You may do this another way, I just personally like this more (more info on this: TextBox Masks and Formats):
function Format(t) -- t is the text from the textbox
return t:gsub("%D", "") -- only allows numerical strings
end
script.Parent:GetPropertyChangedSignal("Text"):Connect(function() -- we use GetPropertyChangedSignal to help determine when the text changes in the textbox
script.Parent.Text = Format(script.Parent.Text) -- makes sure that it fits the format
end)
Now that we have that fancy cool technique done, lets move on to the actual function of the GUI. As always we use debounce to help ensure that a player can’t repeatedly click the button, and possibly break the function. Since I am using a local script in the textbox though, I need to define the textbutton and other children in the frame when confirming a transaction. After that you can add in anything you want the GUI to do before it fire’s a remote event and some data back to the server. It is important to note that, ANYTHING TYPED IN A TEXTBOX IS A STRING! so we will need to use tonumber
to turn the string into a number, just like using tostring
to convert a number to a string. Once you are done with that, you need to make sure you send the number of the text in the textbox to the server when firing. It should look similar to this:
local event = game.ReplicatedStorage.FatbuxP
local a = script.Parent
local c = script.Parent.Parent.TextBox2
event:FireServer(tonumber(a.Text), players:FindFirstChild(c.Text))
As you can see I added a “c.Text” and an “a.Text,” as you may know “a.Text” is the amount Textbox. “c.Text” is an extra thing I added, so you can pick any player in the server to give the currency to. When creating this we have to define all of the players in the server and see if there is a name that matches with the text typed into the textbox. something like this would work:
local players = game:GetService("Players")
local enter = script.Parent.Parent.enter
local d = false
local event = game.ReplicatedStorage.FatbuxP
local a = script.Parent
local c = script.Parent.Parent.TextBox2
enter.MouseButton1Click:Connect(function()
if players:FindFirstChild(c.Text) then -- make sure that player exists
if d == false then -- debounce
d = true
-- code here
d = false
event:FireServer(tonumber(a.Text), players:FindFirstChild(c.Text)) -- sends the data to the server
end
else
-- code here
d = false
end
end)
Changing The Data
Now that you have finished everything GUI wise, you are ready to finish up and give the player their currency. First thing is we have to make sure we correctly add in the data that was sent to the server, then we can finish off by finally giving the player their currency:
game.ReplicatedStorage.FatbuxP.OnServerEvent:Connect(function(player, amt, cmt) -- amt is the number and cmt is the player
if type(amt) ~= "number" then -- checks if it is really a number
print("not a number")
return
end
wait(1)
cmt.Fatbux.Value = cmt.Fatbux.Value + amt -- adds the amount the player asked for to their currency
end)
At the end it should be similar to this little clip:
Extra Information
Pictures Of Whereabouts
Extra stuff I added
1.) I have worked on a cash effect and suffix list for the currency display cash effect:(How To Make A Cool Cash Effect Script In Roblox - YouTube) suffix: (Most efficient way of converting a number in scientific notation into a Suffix and back? - #3 by woot3)
2.) Used my own detail in GUI like the loading/converting effect. (You Probably Already Know Lol)
Here is a downloadable file, so you can get a better understanding of how everything is set up if you are still confused: Test.rbxl (33.6 KB)
Thanks For Reading! If you end up having any trouble with this, make sure to try and contact me, so I can help!