Plr.Chatted Script

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?

You want the command to clone the item?

Sure to clone it and give it to the player

Also is this a local script or a normal script

oh it is a local script cet player will get it

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…

2 Likes

Whoops forgot to add function.

1 Like

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.

There is an extra ) at the end of the line so you might want to remove it.

plr.Chatted:Connect(function(msg)) -- Function that is fired once the "plr" chats. 
1 Like

Thanks for the code but is there a way to check if the player has the item so it wont give him another?

Of course there is, let me do a change on the code.

@igothaked2time, try using the last code, i have changed it. If you get any errors/it doesn’t works, then don’t hesitate to tell us it.

Yes i see i used the code but the player can get inf amounts

Maybe like this?

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 

No it still gives me if i type !sword i want it so if i have the item i cant get another one unless i lose it

You should probably check the character too in the event they have it equipped.

ugh even if i have it equipt i still get it idk why

No, there isn’t an extra ) at the 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)

I said that before he edited it.