Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i give the player an item when they say something?

I dont understand, i tried to give the player something when they say "sword" but it did not work

Code:

game.Players.PlayerAdded:Connect(function(player) 
	player.Chatted:Connect(function(msg) 
		if msg == "sword" then 

			local original = game.ServerStorage.R6Sword
			local copy = original:Clone()
			copy.Parent = game.Players.LocalPlayer.Backpack

		end
	end)
end)

1 answer

✓ Accepted answer

Well first thing, I see you're using LocalPlayer, there is 2 problems with this:

  1. If you give the tool using a LocalScript, it will not be replicated in the server
  2. You're using ServerStorage, LocalScripts cannot access ServerStorage

Plus, it isn't necessary, as we already have the player variable

So instead, put your code in a normal script, here's a version that should work:

local CallMsg = "sword"

local item = game.ServerStorage.R6Sword

game.Players.PlayerAdded:Connect(function(player) 
	player.Chatted:Connect(function(msg) 
		if msg == CallMsg then 

			local original = item
			local copy = original:Clone()
			copy.Parent = player.Backpack

		end
	end)
end)

You can place this script in ServerScriptService if you'd like

Oh and btw, I recommend using ReplicatedStorage to store tools.

1 comment

1

Thanks a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.