What do you want to achieve? Keep it simple and clear!
I want to make it so whenever you type “/give PlayerName ItemName Amount” in the chat, it gives the specified player an specified item and the amount. (Just like in Minecraft)
What is the issue? Include screenshots / videos if possible!
No screenshots/videos because, it’s just too simple to understand and it doesn’t give me any errors.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yeah, nothing helped.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is the code i’ve tried.
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local splitString = string.split(msg," ")
if msg == "/give" then
game.ReplicatedStorage.Cheats.GiveItems:Invoke(game.Players:WaitForChild(splitString[2]), splitString[3], splitString[4])
end
end)
end)
function addItem(inv,name,count,id)
if not M_II[name] then return end
local item = M_II[name]
count = count or 1
local function rep(i)
local slot = inv["Slot"..i]
local tab = S_H:JSONDecode(slot.Value)
if (tab.count and (tab.count > 0)) and (tab.name == name) then
local fit = math.min(count,(item.maxstack or 64) - tab.count)
count = count - fit
tab.count = tab.count and (tab.count + fit) or fit
tab.name = name
slot.Value = S_H:JSONEncode(tab)
if count <= 0 then
return true
end
end
end
local function rep2(i)
local slot = inv["Slot"..i]
local tab = S_H:JSONDecode(slot.Value)
if (tab.count <= 0) or ((tab.count and (tab.count > 0)) and (tab.name == name) or (tab.name == "") or not tab.name) then
local fit = math.min(count,(item.maxstack or 64) - tab.count)
count = count - fit
tab.count = math.max(0,tab.count)
tab.count = tab.count and (tab.count + fit) or fit
tab.name = name
slot.Value = S_H:JSONEncode(tab)
if count <= 0 then
return true
end
end
end
if id then
rep2(id)
end
if count > 0 then
for i=0,35 do
if rep(i) then break end -- do slots that can stack first
end
end
if count > 0 then
for i=0,35 do
if rep2(i) then break end
end
end
if count > 0 then
--spawnItem(name,count)
end
end