What I want to do is create a admin gui where you type in the name of the person you want to give coins to, type in the amount of coins, & hit a button that says “give coins” and it will set their amount of coins to that amount. I’ve tried to do it myself, online, and other methods but I just can’t seem to find it.
Well, if you have the gui set up you could follow this.
- Make a script inside the button that can possibly give the players the coins.
- Inside the script write this.
local Ob = script.Parent
Ob.MouseButton1Click:Connect(function(plr) -- Whenever a player clicks the button
local playerCash = plr.leaderstats.Cash -- Change cash to whatever your currency is called
playerCash.Value = playerCash.Value + 100 -- Change 100 to how much you want to give.
end)
Edit some things in the script and your good to go!
If this code is in a local script it will only give them coins on the client not the server.
You will need an event, to fire this function in a server script.
Put the local script inside the ScreenGui and put the script in ServerScriptService
LocalScript:
local AmountTextBox = script.Parent.AmountTextBox
local PlayerTextBox = script.Parent.PlayerTextBox
local TextButton = script.Parent.TextButton
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
TextButton.MouseButton1Click:Connect(function()
if string.len(AmountTextBox.Text) > 0 and string.len(PlayerTextBox.Text) > 0 then
RemoteEvent:FireServer(PlayerTextBox.Text, AmountTextBox.Text)
end
end)
Script:
local Players = game:GetService("Players")
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local AdminsList = {}
RemoteEvent.OnServerEvent:Connect(function(player, playerto, amount)
if table.find(AdminsList, player.UserId) and string.len(playerto) > 0 and string.len(amount) > 0 then
if Players:FindFirstChild(playerto) then
Players:FindFirstChild(playerto).leaderstats.Coins.Value += amount
end
end
end)
If you want to make a secure admin gui to give the players some coins you should use Remote Events, and UserId checks. If you’re fine without a fancy gui then you can use the dev console.