I have 2 currencies in my game, those being tickets and money. I have a ScreenGui that has a TextBox and a TextButton that allows the player to enter a custom amount of tickets to cash out (if the player owns the amount they have typed in the textbox of course)
The tickets are converted on a rate of 1:2 (1 ticket = 2 money).
The only problem is, I don’t have any idea on how to make it work…
This is what I have tried (It is placed inside the TextButton, in a server script, not local):
button = script.Parent
button.Activated:Connect(function(plr)
local number = button.Text
plr.Tickets.Value -= number
plr.leaderstats.Money.Value += number
end)
(it prints no errors either)
Any sort of help is greatly appreciated.
It would be in your best interest to fire a RemoteEvent when the player clicks the text button. Your code for detecting when the text button is clicked should be a local script in StarterCharacterScripts that fires a remote event, from there you can handle everything on the server.
You’ll need to use a remote event. The button event isn’t picked by server side.
Create a remote event in replicated storage, and give it a name like ConvertCurrency.
add this to a client script:
button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
button.Activated:Connect(function(plr)
local number = button.Text
ReplicatedStorage.ConvertCurrency:FireServer(tonumber(button.Text))
end)
Create a script in server script service, with this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.ConvertCurrency.OnServerEvent:Connect(function(plr, number)
if plr.Tickets.Value < number then return end
plr.Tickets.Value -= number
plr.leaderstats.Money.Value += number
end)
Nevermind, I fixed it, It didn’t mention the textbox correctly
This is the working script (had to change line 5 in local script):
button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
button.Activated:Connect(function(plr)
local number = button.Parent.TextBox.Text
ReplicatedStorage.Remotes.ConvertTicketsRemote:FireServer(number)
end)