I am trying to make a chat command that awards an item. The user is supposed to type the name of the item, but I have to search for the item in a model and it is case sensitive and for some reason it makes the item name from the command lowercase. Ex: Player types "awarditem tjtorin 1 Alien Relic" Error: Can't find alien relic in Model

Commands.awarditem = function(Sender, Args)
	local Player = Args[1]
	local Amount = Args[2]
	local Item = Args[3]
	
	Item = string.gsub(Args[3], "_", " ")
	
	game.ServerStorage.AwardItem:Invoke(Player, game.ReplicatedStorage.Items[Item].ItemId.Value, Amount)
end

-- Full code
local Players = game:GetService("Players")
local Admins = {
	"tjtorin";
	127652021;
}
local prefix = ":"
local Commands = {}

-- COMMANDS
Commands.kill = function(Sender,Args)
	Args = table.concat(Args," ")
	if game.Players:FindFirstChild(Args) then
		game.Players[Args].Character.Head:Destroy()
	else
		game.Players[Sender.Name].Character.Head:Destroy()
	end
end

Commands.givecash = function(Sender,Args)
	local MAX = 2^52
	local MIN = -2^52
	local Player = Args[1]
	local Amount = Args[2]
	--[[if tonumber(Amount) > MAX then
		print("Cash amount is over max")
		Amount = MAX
	end
	if tonumber(Amount) < MIN then
		print("Cash amound is under the min")
		Amount = MIN
	end]]
	if game.Players:FindFirstChild(Player) then
		game.ServerStorage.MoneyStorage:FindFirstChild(Player).Value = game.ServerStorage.MoneyStorage:FindFirstChild(Player).Value + Amount
	end
end

Commands.setcash = function(Sender,Args)
	local MAX = 2^52
	local MIN = -2^52
	local Player = Args[1]
	local Amount = Args[2]
	--if tonumber(Amount) > MAX then
		--print("Cash amount is over max")
		--Amount = MAX
	--end
	--if tonumber(Amount) < MIN then
		--print("Cash amound is under the min")
		--Amount = MIN
	--end
	if game.Players:FindFirstChild(Player) then
		game.ServerStorage.MoneyStorage:FindFirstChild(Player).Value = Amount
	end
end

Commands.awarditem = function(Sender, Args)
	local Player = Args[1]
	local Amount = Args[2]
	local Item = Args[3]
	
	Item = string.gsub(Args[3], "_", " ")
	
	game.ServerStorage.AwardItem:Invoke(Player, game.ReplicatedStorage.Items[Item].ItemId.Value, Amount)
end

Commands.kick = function(Sender,Args)
	local Player = Args[1]
	local Reason = table.concat(Args," ",2)
	if game.Players:FindFirstChild(Player) then
		game.Players[Player]:Kick(Reason)
	else
		print(Player.." does not exist")
	end
end
-----------------

-- FUNCTIONS
local function IsAdmin(Player)
	for _,Admin in pairs(Admins) do
		if type(Admin) == "String" and string.lower(Admin) == string.lower(Player.Name) then
			print(true)
			return true
		elseif type(Admin) == "number" and Admin == Player.UserId then
			return true
		end
		end
		print(false)
	return false
	end

local function ParseMessage(Player,Message)
	Message = string.lower(Message)
	local PrefixMatch = string.match(Message,"^"..prefix)
	
	if PrefixMatch then
		Message = string.gsub(Message,PrefixMatch,"",1)
		local Arguments = {}
		
		for Argument in string.gmatch(Message,"[^%s]+") do
			table.insert(Arguments,Argument)
		end
		
		local CommandName = Arguments[1]
		table.remove(Arguments,1)
		local CommandFunc = Commands[CommandName]
		
		if CommandFunc ~= nil then
			CommandFunc(Player,Arguments)
		end
	end
end

function notify(title,msg)
	game.StarterGui:SetCore("SendNotification",{
		Title = "Admin"; 
		Text = msg;
		Icon = "";
		Duration =  5;
   })
end
------------------

Players.PlayerAdded:Connect(function(Player)
	if IsAdmin(Player) then
		wait(.01)
		notify("Admin!","Looks like your an admin!")
	end
	Player.Chatted:Connect(function(Message,Recipient)
		if not Recipient and IsAdmin(Player) then
			ParseMessage(Player,Message)
		end
	end)
end)

2 comments

0

Post the code where you're calling that function.

0

Please post the only part of the code needed