Error with Items Cloning

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

That everyone gets 3 items in a folder after the game starts

  1. What is the issue? Include screenshots / videos if possible!

Im not sure but i think when the round starts the first player to load gets all the items of the other players like on these screen shots

Plyr 2

Plyr 1

  1. What solutions have you tried so far?

I have tried to search on many forums but i can’t seem to find my error

this is the code that clones the item

--local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Folder1 = RS:WaitForChild("Weapons").Melee
local Folder2 = RS:WaitForChild("Weapons").Ranged
local Folder3 = RS:WaitForChild("Weapons").Special

local inRound = game.ReplicatedStorage.InRound


local plr

game.ReplicatedStorage.GetThePlayer.OnServerEvent:Connect(function(plyr)

	plr = plyr

end)


local function onCharacterAdded(character)
	if inRound.Value == false then
		return
	else
		
	
	local Melee = Folder1:GetChildren()
	local Ranged = Folder2:GetChildren()
	local Special = Folder3:GetChildren()

	
	local MeleeTable = Melee
	local RangedTable = Ranged
	local SpecialTable = Special

	
	
	local MeleeTools = {}
	local RangedTools = {}
	local SpecialTools = {}

	repeat 
		local selectedIndexMelee = math.random(1, #MeleeTable) -- Melee
		table.insert(MeleeTools, MeleeTable[selectedIndexMelee])
		table.remove(MeleeTable, selectedIndexMelee)
		
		local selectedIndexRanged = math.random(1, #RangedTable) -- Ranged
		table.insert(RangedTools, RangedTable[selectedIndexRanged])
		table.remove(RangedTable, selectedIndexRanged)
		
		local selectedIndexSpecial = math.random(1, #SpecialTable) -- Special
		table.insert(SpecialTools, SpecialTable[selectedIndexSpecial])
		table.remove(SpecialTable, selectedIndexSpecial)
	until #MeleeTools >= 1 and  #RangedTools >= 1 and  #SpecialTools >= 1
	-- Numbers of tools going to give

	
	
	 -- Cloning Tools
	for i,v in pairs(MeleeTools) do  -- Melee
		Folder1:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
	
	end
	
	for i,v in pairs(RangedTools) do  -- Ranged
		Folder2:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
	end
	
	for i,v in pairs(SpecialTools) do  -- Special
		Folder3:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
	end
	end
end



game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		onCharacterAdded(Character)
	end)
end)





inRound.Changed:Connect(function() 

	if inRound.Value == true then -- When round starts
		
		if plr.Team == game.Teams.Playing then
			return
		else
			
			for i, v in pairs(game.Players:GetChildren()) do

				wait(1)
				onCharacterAdded()

					

			

			end

		
		end
	end
	
end)






game.Players.PlayerAdded:Connect(function()

	if inRound.Value == true then

		wait(2)
		onCharacterAdded()

	end
end)

I just want to know how i can make all the players have 3 items any help would be appreciated

There were some unusual things in your code.

I thought to go through them and point them out, but then I decided it would be better to just give you a good PlayerAdded() starter file.

I put the script for giving characters tools into a module that you can access from any server script.

Hope it helps!

Here is the file:

GiveTools.rbxl (58.2 KB)

SERVER SCRIPT:

--==============
-- PLAYER ADDED
--==============

local Players = game:GetService("Players")
local InRound = game.ReplicatedStorage.InRound
local Module = require(script.Parent.Module)
Players.CharacterAutoLoads = false
local RESPAWN_DELAY = 4


local function PlayerAdded(Player)

	Player.RespawnLocation = game.Workspace.Spawns.Lobby


	--=================
	-- CHARACTER ADDED
	--=================

	local function CharacterAdded(Character)

		if InRound.Value == true then Module:GiveTools(Player) end



		--===============
		-- HUMANOID DIED
		--===============

		local function HumanoidDied(Character)
			task.wait(RESPAWN_DELAY)
			if InRound.Value == true then Player.RespawnLocation = game.Workspace.Spawns.Map end
			Player:LoadCharacter()
		end
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(HumanoidDied)

	end
	Player.CharacterAdded:Connect(CharacterAdded)
	Player:LoadCharacter()



	--====================
	-- CHARACTER REMOVING
	--====================

	local function CharacterRemoving(Character)

		-- do stuff

	end
	Player.CharacterRemoving:Connect(CharacterRemoving)

end
for _, Player in Players:GetPlayers() do
	task.spawn(PlayerAdded, Player)
end
Players.PlayerAdded:Connect(PlayerAdded)



--=================
-- PLAYER REMOVING
--=================

local function PlayerRemoving(Player)

	local PlayerName = Player.Name
	local PlayerUserID = Player.UserId

	-- do stuff

end
Players.PlayerRemoving:Connect(PlayerRemoving)

MODULE SCRIPT:

local module = {}


--============
-- GIVE TOOLS
--============

local MeleeTools = game.ReplicatedStorage.Weapons.Melee:GetChildren()
local RangedTools = game.ReplicatedStorage.Weapons.Ranged:GetChildren()
local SpecialTools = game.ReplicatedStorage.Weapons.Special:GetChildren()

function module:GiveTools(Player)
	game.ReplicatedStorage.Weapons.Melee:FindFirstChild(tostring(MeleeTools[math.random(1, #MeleeTools)])):Clone().Parent = Player.Backpack
	game.ReplicatedStorage.Weapons.Ranged:FindFirstChild(tostring(RangedTools[math.random(1, #RangedTools)])):Clone().Parent = Player.Backpack
	game.ReplicatedStorage.Weapons.Special:FindFirstChild(tostring(SpecialTools[math.random(1, #SpecialTools)])):Clone().Parent = Player.Backpack
end

return module

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