I created a script that would check that would give a player two random guns in game, because the main script only gives players guns once the round starts. There would be a problem where players did not have a gun if they joined after the round started, and they had to wait until the next round to get one. I created a script to fix this issue, which is down below, but I don't know what exactly is wrong with it.
InProgress is controlled by a seperate script which controls the map changing.
This is a simple script overall, but to my knowledge it should work. Any help would be great.
local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:FindFirstChild("InProgress") -- InProgress is a value to determine if there is a game going on or not
while true do
wait(.1)
if status.Value == 'Game' -- InProgress is changed to this once a round begins
then
while true do
function onPlayerEntered(newPlayer)
for _, player in pairs(game.Players:GetPlayers()) do
local randomgun = game.ReplicatedStorage:FindFirstChild('Pri'):GetChildren()
local gun1 = randomgun[math.random(1, #randomgun)]
gun1:Clone().Parent = player.Backpack
gun1:Clone().Parent = player.StarterGear
local randomgun2 = game.ReplicatedStorage:FindFirstChild('Sec'):GetChildren()
local gun2 = randomgun2[math.random(1, #randomgun2)]
gun2:Clone().Parent = player.Backpack
gun2:Clone().Parent = player.StarterGear
script.Sound:Play() -- this would usually help me to identify if the script went through or not
wait(.5)
end
end
end
else
if
status.Value == 'Lobby' -- Inprogress is changed back to this when the round is over, and the players are in the lobby
then
wait(3)
end
end
end
