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

How can I give players tools from a folder?

Hey guys. I am working on a game where a different battlefield is loaded every round and players are given tools depending on the battlefield that has been chosen. I have tried to add a folder within each "battlefield" called "tools" and I have added tools that I want the players to be given upon being teleported in.

Here is a concept of what I want to do...

-- This script runs right after players are teleported
	local plrs = game.Players:GetChildren()
	for i = 1,#plrs do
		local num = math.random(1,8)
		plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
		plrs[i].Character.Parent = workspace.Ingame
		plrs[i].Character.Humanoid.Health = plrs[i].Character.Humanoid.MaxHealth
		local tools = curmap.tools:GetChildren()
-- From here...
		tools:clone().Parent = plrs.Backpack
-- To here is just an idea of what I want to do.

I am quite new to lua scripting, and i'm not sure how I would go about doing this.

Any pointers or help is much appreciated!

1 comment

0

clone them into StarterPack not Backpack

1 answer

for i, v in pairs(game.Players:GetPlayers()) do
	local curmap = workspace.Model -- Change this to the curmap location, or remove if previously set
	if workspace:FindFirstChild(v.Name) ~= nil and workspace[v.Name]:FindFirstChild("Humanoid") ~= nil and workspace[v.Name]:FindFirstChild("Head") ~= nil then
		local num = math.random(1, 8)
		workspace[v.Name].Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
		workspace[v.Name].Humanoid.Health = workspace[v.Name].Humanoid.MaxHealth
		workspace[v.Name].Parent = workspace.Ingame
		local tools = curmap.tools:GetChildren()
		-- Clone Tools
		for c, d in pairs(tools) do
			d:Clone().Parent = v.Backpack
		end
	end
end

Firstly, you can use :GetPlayers() instead of :GetChildren() since it will only get the actual players, in-case something else gets into the player service

Next, the GetChildren() produces a table, so you can't call the tools as you attempted on line 10 (also, "clone" needs to be capitalized), and instead need to iterate through this table as well with a for loop

1 comment

0

When I tried this, only one player was being teleported and the game would not continue after "We'll be playing map name here"

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