Give a tool stored in ServerStorage to a player when I chat "-unlockweapon(Player's Username)"

The title says it all. I need to find a way on how to give a player a tool that is stored somewhere like ServerStorage only when I (TyKing_22) send in a chat saying “-unlockweapon(Player’s Username)”

1 Like
game.Players.PlayerAdded:Connect(function(plr) -- plr joins
	plr.Chatted:Connect(function(msg) -- plr chats
		if string.lower(msg) == "-unlockweapon" and plr.UserId = YOURUSERID then -- make it not case sensitive
			local tool = game.ServerStorage.Tool:Clone() -- clone tool
			tool.Parent = plr.Backpack -- give it to the player
		end
	end)
end)
3 Likes

hey before I try this (thank you btw) where would this local script be placed?

2 Likes

make it a serverscript and put it in serverscript storage. Localscripts can’t make serverside changes (i.e only that player will see that they have that tool)

4 Likes

This should be a Script placed in ServerScriptService or Workspace.

2 Likes

Hey thank you so much! this works but how do I make it to where when I type “-unlockweapon(Player’s Username)” It’ll give that player the weapon?

2 Likes

In that case, you can try this script:

local Admins = {""}
local Prefix = "-" 

game.Players.PlayerAdded:Connect(function(plr)
	for _,v in pairs(Admins) do
		if plr.Name == v then
			plr.Chatted:Connect(function(msg)
				local loweredString = string.lower(msg)
				local args = string.split(loweredString," ")
				if args[1] == Prefix.."unlockweapon" then
					for _,player in pairs(game:GetService("Players"):GetPlayers()) do
						if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
							player.Character.Humanoid.WalkSpeed = args[3]
						end
					end
				end
			end)
		end
	end
end)

EDIT: Please note that it is important to understand what this script does before actually using it to prevent further devforum posts like this. Also make sure you put your username inside the Admins table.

2 Likes

hey whenever I type the command with a different player’s name… it will give me the weapon and not give it to the player I typed in.

1 Like

this is my script:

local Admins = {"TyKing_22", "AkarixVoid"}
local Prefix = "-" 

game.Players.PlayerAdded:Connect(function(plr)
	for _,v in pairs(Admins) do
		if plr.Name == v then
			plr.Chatted:Connect(function(msg)
				local loweredString = string.lower(msg)
				local args = string.split(loweredString," ")
				if args[1] == Prefix.."unlockcursedvoid" then
					for _,player in pairs(game:GetService("Players"):GetPlayers()) do
						if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
							local tool = game.ServerStorage.Cursed:Clone()
							tool.Parent = plr.Backpack
						end
					end
				end
			end)
		end
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.