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

How would I clone an item for each player in the server?

The maximum number of players in a server is 4 and I want a table that has a gun for each player so that they cannot take more than needed, but if there are less than 4 players in the game then I want it to only show that number of guns on the table

This is what I have gotten so far

local Players = game:GetService("Players")
local players = Players:GetPlayers()
local replicatedstorage = game.ReplicatedStorage
local clonegun = replicatedstorage.Gun:Clone()
local clonegun2 = replicatedstorage.Gun2:Clone()
local clonegun3 = replicatedstorage.Gun3:Clone()
local clonegun4 = replicatedstorage.Gun4:Clone()

if #players == 1 then
	clonegun.Parent = game.Workspace
end

everytime I join the game there appears to be no guns anywhere in the workspace

5 comments

0

are all 4 guns the exact same?

0

yes

0

When you define players, it gets the table from that time, so it #players will stay zero until you update it. Also why do you need to wait for players to add the guns?

0

also the if statement only checks #players once. You should make a while loop to check it every second.

0

Hi i saw your comment check bedlow for an edited script to change position of your gun

1 answer

✓ Accepted answer

Assuming all 4 guns are the same, you could make a for loop that goes through all the players..

wait(3)
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local replicatedstorage = game.ReplicatedStorage
for i,v in pairs(players) do
	local clonegun = replicatedstorage.Gun:Clone()
	clonegun.Parent = game.Workspace
	clonegun.Position = Vector3.new() -- inside your brackets write the position you want to send your gun to e.g. (1,1,1)
end

1 comment

0

Actually it seems that i have all the guns in different positions so do you have anyway that i could fix this without moving them to the same position?

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