how to change a players money in Roblox studio
e.g what I mean is I want a GUI that when I type a players name in it and press submit you can change how much money you want them to have
A lot of ways, 1 you could just implement this in the Command Bar ingame:
game.Players.JadtrugamingYT1.Money.Value = 50
what i mean is i want a gui that when i type a players name in it and press submit you can change how much money you want them to have
In order to assist you, we first need information on how your data/values are handled such as where they are located, how they are normally changed, ect. This post is extremely vague and without the right information no one will be able to assist you.
EDIT: Also, please keep in mind this is a category for support, if you are just looking for someone to write code for you (Obviously there are cases where code samples/examples are merited) then this is not the place.
It’s pretty simple, if your saying inside studio then click the Server button on the topbar then go to the explorer, open leaderstats and change the value.
If your talking about scripts then put this inside your code:
local player = game.Players:FindFirstChild('username') -- replace username with the players username
if player then
player.leaderstats.Cash.Value = 500 -- replace 'Cash' with the currency name
end
(Note: If your using a LocalScript then you’ll need to use a RemoteEvent so the new currency amount can be shown to the server.)
To answer your question here one way you can do this is have an Admin-Only GUI which is only replicated to those who have permission to it via a UserId or even Group Rank system in which you enter the players Username and the amount of money you wish into the GUI and the GUI fires a remote event to the server to check if that player exists, if the player exists it adds said amount of the money you wish to their data.
You can make it basic:
Local script inside StarterGui:
local Gui = script.Parent
local SumbitButton = Gui.SumbitButton
local PlayerTextBox = Gui.PlayerTextBox
local ValueTextBox = Gui.ValueTextBox
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
SumbitButton.MouseButton1Click:Connect(function()
if PlayerTextBox.Text ~= "" and ValueTextBox.Text ~= "" then
RemoteEvent:FireServer(PlayerTextBox.Text, ValueTextBox.Text)
end
end)
Server Script inside ServerScriptService:
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
RemoteEvent.OnServerEvent:Connect(function(plr,PlayerToGive,ValueToGive)
local PlayerGive = game:GetService("Players"):FindFirstChild(tostring(PlayerToGive))
if PlayerGive then
PlayerGive.leaderstats.Money.Value += tonumber(ValueToGive) --change the location if you want since we don't know how you have it organized
else
return warn("Player does not exist")
end
end)
ok thank youuuuuuuuuuuuuu I will try it out
Please make sure you added: 1. RemoteEvent with name RemoteEvent to ReplicatedStorage and also insert two TextBoxes one which will be representing player’s name and one which will be representing the value you want to give and also make TextButton/ImageButton with name SumbitButton so you will be able to run the code :).
Well I made typo on SumbitButton instead of Submit but never mind :D.
{DELETED ANSWER}
I just realizated that it dosen’t work
This won’t work because if you change this by local script you are gonna change it only for the client not for server if you want to change something on server you need to use RemoteEvents/Functions.
Use sleitnick’s datastore editor
Lemme see,
–local script in the submit button
local button = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --Here, Event is the name I gave my remote event. Create a remote event in replicated storage and put the name in the (" ")
local textBox = -- reference your text box here
local typedPlayer
button.MouseButton1Up:Connect(function()
if textBox.Text ~= "" then
typedPlayer = textBox.Text
else
print("no text")
end
event:FireServer(textBox.Text) -- here we send the player name we typed
end)
–Server script in the ServerScriptService
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --again, get the event name
event.OnServerEvent:Connect(function(player, typedPlayer)
for _, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == string.lower(typedPlayer) then
-- found a player
local plr = player
local currency = -- for example: plr.leaderstats.Cash
if currency then
currency.Value += 50 -- fifty is the amount of currency they receive
end
else
--nothing happens
end
end
end)
If this does not work or is written incorrectly in any way please tell me. I do not want to give bad info. Also, if you want to have another textbox where you type in the amount a currency you wish to give them, i can edit my code.
ok you could just change the leaderstat but keeping your values in leaderstats is bad idea as exploiters can go like: ‘oh let me change leaderstat to 10^3003’
so just make it so like there is text input and you type in player name and when you type in the value your variable is changed (which is tautology)
what even I am saying
You could have it in the same text box!
–local script in the submit button
local button = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --Here, Event is the name I gave my remote event. Create a remote event in replicated storage and put the name in the (" ")
local textBox = -- reference your text box here
local typedText
local plr
local value
button.MouseButton1Up:Connect(function()
if textBox.Text ~= "" then
typedText = textBox.Text
local splitText = string.split(typedText, " ") -- for example: >> "John", "50". Fifty is the amount of currency and John is the player
plr = splitText[1]
value = splitText[2]
else
print("no text")
end
if value ~= nil and plr ~= nil then
event:FireServer(plr, value) -- here we send the player and the value
end
end)
–Server script in the ServerScriptService
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --again, get the event name
event.OnServerEvent:Connect(function(player, playerToGiveCash, CashValue)
for _, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == string.lower(playerToGiveCash) then
-- found a player
local plr = player
local currency = -- for example: plr.leaderstats.Cash
if currency and CashValue then
currency.Value += tonumber(CashValue) --CashValue is the amount of currency they receive
end
else
--nothing happens
end
end
end)
Again, If this does not work or is written incorrectly in any way please tell me. I do not want to give bad info. Also, if you want to have another textbox where you type in the amount a currency you wish to give them, i can edit my code.
That’s why we use remote events, to prevent people from doing things like that. The server checks the values.
Look for the reply I posted. You can have it all in one textbox!
Just a reminder that this kind of stuff can be exploited sometimes (depends on your code) by using the remotes if your remote is being fired to the server.
Example:
game.ReplicatedStorage.RemoteEvent:FireServer(
game.Players.LocalPlayer.Name,
999999999999
)
-- gives the exploiter tons of cash
or
for i = 1, 1999 do
game.ReplicatedStorage.RemoteEvent:FireServer(
game.Players.LocalPlayer.Name
)
end
-- well for this method you can add a cooldown
Edit: Just realized that you could add a whitelist which would probally fix this problem with exploiting on the serverside script.
You could create a table full of players who can fire the event.
–local script in the submit button
local button = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --Here, Event is the name I gave my remote event. Create a remote event in replicated storage and put the name in the (" ")
local textBox = -- reference your text box here
local typedText
local plr
local value
button.MouseButton1Up:Connect(function()
if textBox.Text ~= "" then
typedText = textBox.Text
local splitText = string.split(typedText, " ") -- for example: >> "John", "50". Fifty is the amount of currency and John is the player
plr = splitText[1]
value = splitText[2]
else
print("no text")
end
if value ~= nil and plr ~= nil then
event:FireServer(plr, value) -- here we send the player and the value
end
end)
–Server script in the ServerScriptService
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("Event") --again, get the event name
local playersWithAccess = {"John","bob"}
event.OnServerEvent:Connect(function(player, playerToGiveCash, CashValue)
if playersWithAccess[player] then
for _, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == string.lower(playerToGiveCash) then
-- found a player
local plr = player
local currency = -- for example: plr.leaderstats.Cash
if currency and CashValue then
currency.Value += tonumber(CashValue) --CashValue is the amount of currency they receive
end
else
--nothing happens
end
end
else
print("nope")
end
end)