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!
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