Weapons are not issued during the round

I need weapons to be issued to players during the round, but something doesn’t work out. could you please help?

local weapons = ReplicatedStorage.Weapons
local remote = ReplicatedStorage.PickWeapon
local function giveweapon(player)
	for i = 1, giveweapons do
		while true do
			local rand = math.random(1, #weapons:GetChildren())
			local randomWeapon = weapons:GetChildren()[rand]

			if not player.Backpack:FindFirstChild(randomWeapon.Name) then
				randomWeapon:Clone().Parent = player.Backpack
				break
			end
		end
	end
end
remote.OnServerEvent:Connect(function(player)
	giveweapon(player)
end)

here’s the whole sсript for you, just in case

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local workspace = game:GetService("Workspace")
local lobby = workspace:WaitForChild("Spawn")
local maps = ReplicatedStorage.Maps:GetChildren()
local status = ReplicatedStorage.Status
local duelteam = game.Teams.Duelists
local lobbyteam = game.Teams.Lobby
local giveweapons = 1
local weapons = ReplicatedStorage.Weapons
local remote = ReplicatedStorage.PickWeapon
local function giveweapon(player)
	for i = 1, giveweapons do
		while true do
			local rand = math.random(1, #weapons:GetChildren())
			local randomWeapon = weapons:GetChildren()[rand]

			if not player.Backpack:FindFirstChild(randomWeapon.Name) then
				randomWeapon:Clone().Parent = player.Backpack
				break
			end
		end
	end
end
remote.OnServerEvent:Connect(function(player)
	giveweapon(player)
end)
while true do
	local players = Players:GetPlayers()
	for _, player in pairs(players) do
		player.Team = lobbyteam
	end
	if #players >= 2 then
		for i = 5, 0, -1 do
			status.Value = "Intermission: " .. i
			wait(1)
		end
		local chosenmap = maps[math.random(1, #maps)]
		local clonemap = chosenmap:Clone()
		clonemap.Parent = workspace
		status.Value = "Map: " .. clonemap.Name
		wait(2.5)
		local chosenplayer1 = players[math.random(1, #players)]
		local chosenplayer2 = nil
		repeat
			chosenplayer2 = players[math.random(1, #players)]
		until chosenplayer2 ~= chosenplayer1
		chosenplayer1.Character:SetPrimaryPartCFrame(clonemap.Teleport1.CFrame)
		chosenplayer1.Team = duelteam
		chosenplayer2.Character:SetPrimaryPartCFrame(clonemap.Teleport2.CFrame)
		chosenplayer2.Team = duelteam
		local function handlePlayerDeath(player)
			player.Team = lobbyteam
		end
		chosenplayer1.Character:WaitForChild("Humanoid").Died:Connect(function()
			handlePlayerDeath(chosenplayer1)
		end)
		chosenplayer2.Character:WaitForChild("Humanoid").Died:Connect(function()
			handlePlayerDeath(chosenplayer2)
		end)
		for i = 10, 0, -1 do
			status.Value = "Liquidation: " .. i
			local playing = {}
			if chosenplayer1.Team == duelteam then
				table.insert(playing, chosenplayer1)
			end
			if chosenplayer2.Team == duelteam then
				table.insert(playing, chosenplayer2)
			end
			if #playing == 0 then
				status.Value = "The duelists died"
				wait(3)
				break
			end
			if #playing == 1 then
				status.Value = playing[1].Name .. " has WON!"
				wait(3)
				break
			end
			wait(1)
			if i == 0 then
				local sound = ReplicatedStorage:WaitForChild("kid fav blinker")
				sound:Play()
				wait(0.7)
				chosenplayer1.Character.Humanoid.Health = 0
				chosenplayer2.Character.Humanoid.Health = 0
				status.Value = "Explosive draw!"
				wait(3)
			end
		end
		clonemap:Destroy()
		chosenplayer1.Character:SetPrimaryPartCFrame(lobby.Tp1.CFrame)
		chosenplayer1.Team = lobbyteam
		chosenplayer2.Character:SetPrimaryPartCFrame(lobby.Tp2.CFrame)
		chosenplayer2.Team = lobbyteam
	else
		status.Value = "You're unlikely to play alone."
		wait(0.5)
		status.Value = "You're unlikely to play alone.."
		wait(0.5)
		status.Value = "You're unlikely to play alone..."
		wait(0.5)
	end
end
1 Like

as far as I understand, weapons should be given to players, but nothing happens, there is not even a mistake, maybe I messed up something

try changing

remote.OnServerEvent:Connect(function(player)
	giveweapon(player)
end)

to

remote.OnServerEvent:Connect(giveweapon)

end)
local character = script.Parent
local plr = game.Players:GetPlayerFromCharacter(character)
local remote = game.ReplicatedStorage.PickWeapon
if plr.Team == "Duelists" then
	remote:FireServer()
end

unfortunately, it didn’t help. perhaps this script will help you?

Screenshot 2024-01-31 171724

Try adding a print after the then so we are 100% sure its passing the check.
then tell me if it prints out or not

Also, add a print here so we know the event is actually firing.

nothing was printed on the command line:(


That means there is something with the local script.

Try removing the check in the local script to see if it works.

and use this in the server script

remote.OnServerEvent:Connect(giveweapon)

end)

when I used your hint, my script broke. please tell me how to uncheck the script

1 Like

You should thread that while loop

local Task 
Task = task.spawn(function()
	while task.wait() do
		local rand = math.random(1, #weapons:GetChildren())
		local randomWeapon = weapons:GetChildren()[rand]

		if not player.Backpack:FindFirstChild(randomWeapon.Name) then
			randomWeapon:Clone().Parent = player.Backpack
			task.cancel(Task)
			break
		end
	end
end)
1 Like

You just remove the if plr.team part (or just comment it out)

I’ll try your methods tomorrow. thank you in advance for responding. I really appreciate it.

1 Like

Oh yeah, btw, here’s how functions with the player variable in them work

also no problem :smiley: always happy to help

unfortunately, your method completely destroyed the game script :((



Did I do the right thing? or does something need to be changed? :thinking:

hover over the End) in the server script and tell me what it says

image

there is a end there that needs to be removed

If you’re up for it, you could possibly add me to Team Create so I can help you that way.

it’s a good idea. but I am not a native English speaker, so I do not know how I can write to you. I will be able to add you to Team Create in 20-30 minutes

sure, let me send you a friend request so you can add me