So i’ve been working to find out a way to make it so when i type ![Text]
The player would get items
Like !shinobi and they will get 5 items This is what i tried
local Players = game:GetService(“Players”) - the player who said it
local ServerStorage game:GetService(“Acony”) - the item you get
local GetItem = “!Sword” - the command you type
end
Im new to scripting so i would like to know if the “Getitem” is even a code line?
local plr = game.Players.LocalPlayer -- The Player
local Item = game.ServerStorage:WaitForChild("Acony") -- The Item
plr.Chatted:Connect(function(msg) -- Function that is fired once the "plr" chats.
if msg = "!Sword" then -- Checks if what the player said is the correct text.
if plr.Backpack:FindFirstChild("Acony") then return print("Player has item already.") -- Cheks if the player has the item already, if he does, print Player has item already, though if he doesn't has, then give the player it.
else Clone().Parent = plr.Backpack -- Clones the item and puts it at the backpack of the player
end
end
end)
You should start by looking at tutorials on how to do this kind of stuff, and know the basics of scripting, but there it is, free code…
There is though, since if the player says “ok ok ok”, it will give them the item, he is looking for the player to say something he wants, to then he get the item.
local plr = game.Players.LocalPlayer -- The Player
local Item = game.ServerStorage:WaitForChild("Acony") -- The Item
plr.Chatted:Connect(function(msg) -- Function that is fired once the "plr" chats.
if msg = "!Sword" then -- Checks if what the player said is the correct text.
if plr.Backpack:FindFirstChild("Acony") then return print("Player has item already.") -- Cheks if the player has the item already, if he does, print Player has item already, though if he doesn't has, then give the player it.
else Item:Clone().Parent = plr.Backpack -- Clones the item and puts it at the backpack of the player
end
end
You need to use a server script for this, not a local script. On player added, listen for the player.Chatted event. When it’s called you can compare the message sent to your command, if it matches then clone the appropriate tools.
To check it the player already has an item you can tag items cloned with collection service, then check if they still exist under the players character or backpack.
local ShinobiItems = {
game.ServerStorage["Acony"],
}
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if msg:lower():sub(1,8) == "!shinobi" then
for i,v in pairs(ShinobiItems) do
local Found = false
for x,c in pairs(Player.Backpack:GetChildren()) do
if c.Name == v.Name then
Found = true
end
end
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character then
for x,c in pairs(Character:GetChildren()) do
if c.Name == v.Name then
Found = true
end
end
end
if not Found then
local Item = v:Clone()
Item.Parent = Player.Backpack
end
end
end
end)
end)