Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 2 years ago

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

0
are all 4 guns the exact same? sne_123456 439 — 2y
0
yes DahNOOB_TY 4 — 2y
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? msculenny 42 — 2y
0
also the if statement only checks #players once. You should make a while loop to check it every second. msculenny 42 — 2y
0
Hi i saw your comment check bedlow for an edited script to change position of your gun sne_123456 439 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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
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? DahNOOB_TY 4 — 2y
Ad

Answer this question