I want to make it so that the player’s Gold can be adjusted with a command for example “/addcoins [player_name]” (for admins/ certain players)
It is NOT doing what I wanted
I’ve tried searching around for me to add numbers into IntValues through a script
this is the OnPlayerAdded script:
local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")
Players.PlayerAdded:Connect(function(player)
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 200
gold.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = player
local placedTowers = Instance.new("IntValue")
placedTowers.Name = "PlacedTowers"
placedTowers.Value = 0
placedTowers.Parent = player
player.CharacterAppearanceLoaded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Player")
end
end
end)
end)
I ended up deleting the entire script, so it would be a nice thing if you guys were to help me make a new one.
For the Admins Only command i would use the “Player.Chatted” event.
Create a server script in ServerScriptService and do the following:
--// Services //--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables //--
local Prefix = "/" -- Change whatever you want the prefix to be
local Command = "/AddCoins" -- Change the command name whatever you want it to be
local Admins = {"DevChams", "CoolGuy123"} -- Admins (Username only)
local Chat_MSG_Event = Instance.new("RemoteEvent")
Chat_MSG_Event.Name = "Chat_MSG"
Chat_MSG_Event.Parent = ReplicatedStorage
--// Functions //--
local function Add_Coins(Player, Amount)
local Gold = Player:WaitForChild("Stats").Gold
Gold.Value += Amount
end
Players.PlayerAdded:Connect(function(Player)
--// ADD COINS VALUE //--
local Configurations = Instance.new("Configuration")
Configurations.Name = "Stats"
Configurations.Parent = Player
local Gold = Instance.new("IntValue")
Gold.Name = "Gold"
Gold.Value = 200
Gold.Parent = Player:WaitForChild("Stats")
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = Player:WaitForChild("Stats")
local placedTowers = Instance.new("IntValue")
placedTowers.Name = "PlacedTowers"
placedTowers.Value = 0
placedTowers.Parent = Player:WaitForChild("Stats")
--// ADD COINS CHAT //--
Player.Chatted:Connect(function(Chat_MSG)
local Admin = false
if string.sub(Chat_MSG, 1, 1) == Prefix then
local EmptyString = string.split(Chat_MSG, " ")
local EmptyString2 = string.split(Chat_MSG, " ")
if EmptyString[1] == Command then
local AddCoinsPlayer = game.Players:FindFirstChild(EmptyString[2])
local Amount = EmptyString2[3]
if not AddCoinsPlayer then
return
end
Admin = false
for i,v in pairs(Admins) do
if v == Player.Name then
print(Player.Name .. " is admin.")
Admin = true
if Admin == true then
Add_Coins(AddCoinsPlayer, Amount) -- Amount of coins you want to give
wait(0.25)
Chat_MSG_Event:FireAllClients(AddCoinsPlayer, Amount)
end
elseif v ~= Player.Name then
warn("You aren't admin!")
end
end
end
else
warn("Something went wrong.")
end
end)
end)
If you want an additional cool chat message add a localscript in StarterGui and paste:
--// SERVICES //--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
--// VARIABLES //--
local Chat_MSG_Event = ReplicatedStorage:WaitForChild("Chat_MSG")
--// FUNCTIONS //--
Chat_MSG_Event.OnClientEvent:Connect(function(AddCoinsPlayer, Amount)
StarterGui:SetCore("ChatMakeSystemMessage",{
Text = "[SERVER]: An admin gave someone some coins 👀",
Font = Enum.Font.SourceSansSemibold,
Color = Color3.fromRGB(255, 231, 110),
FontSize = Enum.FontSize.Size10
})
end)
And this is the final result! I hope this helped you with your script , make sure to mark it as solution if it works in-game.
Hello stem!
I know that @DevChams made a system 1000% coolest than mine, but even so I decided to send it because I spent +or- half an hour scripting it, so eh…
local PhysicsService = game:GetService("PhysicsService")
local Admins = {1531615335} -- Change it to your admins ID's
function getplayers(abv)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:sub(1,abv:len()):lower() == abv:lower() then
return v
end
end
end
function darmoedas(plr, valor, player)
if valor >= "1" then
plr.Gold.Value += valor
print("Added "..valor.." coins to "..plr.Name..". Command author: "..player.Name)
else
print("The value to be given must be greater than or equal to 1.")
end
end
Players.PlayerAdded:Connect(function(player)
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 200
gold.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = player
local placedTowers = Instance.new("IntValue")
placedTowers.Name = "PlacedTowers"
placedTowers.Value = 0
placedTowers.Parent = player
player.CharacterAppearanceLoaded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Player")
end
end
end)
player.Chatted:Connect(function(msg)
local split = msg:split(" ")
local comando = split[1]:lower()
if comando == "/addcoins" then
if table.find(Admins,player.UserId) then
local plr = getplayers(split[2])
if plr == nil then
print("Player not found.")
else
darmoedas(plr, split[3], player)
end
else
print("No command access.")
end
end
end)
end)