Command not working, "!btools"

Hey, everybody!
Hope you’re having a good day, mine is fine!
I just can’t figure out how to make this !btools command work.

Concept:

When a user that is in a group, (rank 12 or over) states the command “!btools”, it will give them btools from the workspace.

Code:

local minrank = 12
local btools = game.Workspace["Building Tools"]
local Storage = game.Workspace
local ToolNames = {"Building Tools"}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(Message)
	    if Message == "!btools" then
	        if player:GetRankInGroup(GroupID) >= minrank then
				local Backpack = player:WaitForChild("Backpack")
					for i = 1, #ToolNames do
						local Tool = Storage:FindFirstChild(ToolNames[i])
					if Tool then
						end
				end
			end
		end
	end)
end)

I really need somebody to help me, I have been sitting here for ages trying to work out how!
Thank you,
Hope you’re having a nice day.

1 Like

You need to clone the tool and parent the tool to the backpack

Do not use workspace as storage. use serverstorage instead of workspace.

1 Like

Hmm… Still not working! Thank you anyways.

Hello, could you please tell me how to do this? I’m new to scripting, sorry.

Are you testing on studio? player:GetRankInGroup dont work in studio.

Whoops! I am, I should’ve tried this before I came to the DevForum… Sorry!

And this section is also wrong. try changing to this:

						local Tool = Storage:FindFirstChild(ToolNames[i])
					        Tool:Clone().Parent = player

Hang on, It does… I have a ticket giver, I tested that in studio and it worked…

OH WAIT… Whoops. I forgot I was on a different account.

1 Like

You can debug with making breakpoints, try if code is working

--[[
I fixed the code and added the cloning and parenting for you. Enjoy!
]]


local minrank = 12
local Storage = game:WaitForChild('ServerStorage')
local ToolNames = {"Building Tools"} -- Add tool names here, make sure they're in serverstorage. :)

local cmd = "!btools"

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(Message)
	    if string.sub(Message, 1, #cmd):lower() == cmd then
	        if player:GetRankInGroup(GroupID) >= minrank then
				for _, v in pairs(Storage:GetChildren()) do
					v:Clone().Parent = player:WaitForChild("Backpack")
				end
			end
		end
	end)
end)

I’ve tested this in my own place, and it works perfectly. Enjoy.

1 Like

Switch those {} to []. It makes the script think your making a table.

Lua is not JavaScript - the table operator works for dictionary and array types. Replacing it with [] would cause a syntax error.