Hi Developers!
During the first round every weapon works fine, but in the 2nd round some weapons randomly just don’t work. They exist in Backpack on Client and on Server sides, like it doesn’t want to render or something.
Here are some scripts related to it:
Pick weapons from loadout
local tweenService = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local weaponsFolder = plr:WaitForChild("Weapons")
local weaponClasses = {weaponsFolder.Historical, weaponsFolder.Unnatural}
local weaponTypes = {weaponsFolder.Historical:GetChildren(), weaponsFolder.Unnatural:GetChildren()}
local loadout = script.Parent:WaitForChild("Loadout")
local primary = nil
local secondary = nil
local melee = nil
local function updateLoadout()
loadout.WeaponsEquipped.Text = ""
if primary ~= nil then
loadout.WeaponsEquipped.Text = "Primary: " .. primary.Name
game.ReplicatedStorage.EquipWeaponRE:FireServer(primary)
script.Parent.Parent.Parent.Parent.Primary.Value = primary
else
return
end
if secondary ~= nil then
loadout.WeaponsEquipped.Text = loadout.WeaponsEquipped.Text .. "\nSecondary: " .. secondary.Name
game.ReplicatedStorage.EquipWeaponRE:FireServer(secondary)
script.Parent.Parent.Parent.Parent.Secondary.Value = secondary
else
return
end
if melee ~= nil then
loadout.WeaponsEquipped.Text = loadout.WeaponsEquipped.Text .. "\nMelee: " .. melee.Name
game.ReplicatedStorage.EquipWeaponRE:FireServer(melee)
script.Parent.Parent.Parent.Parent.Melee.Value = melee
else
return
end
end
updateLoadout()
for i, weaponClass in ipairs(weaponClasses) do
local newButton = script.WeaponClassButton:Clone()
newButton.Text = weaponClass.Name
newButton.Parent = loadout.WeaponClasses
newButton.MouseButton1Click:Connect(function()
for i, child in pairs(loadout.TypesList:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
for i, child in pairs(loadout.WeaponsList:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
for i, weaponType in ipairs(weaponClass:GetChildren()) do
local newTypeButton = script.WeaponTypeButton:Clone()
newTypeButton.Text = weaponType.Name
newTypeButton.Parent = loadout.TypesList
newTypeButton.MouseButton1Click:Connect(function()
for i, child in pairs(loadout.WeaponsList:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
for i, weaponChild in ipairs(weaponType:GetChildren()) do
local newWeaponButton = script.WeaponButton:Clone()
newWeaponButton.Text = weaponChild.Name
newWeaponButton.Parent = loadout.WeaponsList
newWeaponButton.MouseButton1Click:Connect(function()
if weaponType.Name == "Primary" then
primary = weaponChild
script.Parent.StrPrimary.Value = weaponChild.Name
elseif weaponType.Name == "Secondary" then
secondary = weaponChild
script.Parent.StrSecondary.Value = weaponChild.Name
elseif weaponType.Name == "Melee" then
melee = weaponChild
script.Parent.StrMelee.Value = weaponChild.Name
end
updateLoadout()
end)
end
end)
end
end)
end
assigning weapons (server-side):
local rs = game.ReplicatedStorage
local re = game.ReplicatedStorage:WaitForChild("EquipWeaponRE")
local re2 = game.ReplicatedStorage:WaitForChild("DeployRE")
local primary
local secondary
local melee
--giving remote events
local GiveFolder = game.ReplicatedStorage.WeaponGivingHandlers
local giveprimary = GiveFolder.GivePrimary
local givesecondary = GiveFolder.GiveSecondary
local givemelee = GiveFolder.GiveMelee
re.OnServerEvent:Connect(function(plr, gun)
local weapons = plr.Weapons
if gun and gun.Parent.Parent.Parent == weapons then
local gunType = gun.Parent.Name
if gunType == "Primary" then
giveprimary:FireClient(plr, gun)
primary = gun
end
if gunType == "Secondary" then
givesecondary:FireClient(plr, gun)
secondary = gun
end
if gunType == "Melee" then
givemelee:FireClient(plr, gun)
melee = gun
end
end
end)
rs.WeaponGivingHandlers.ToServer.ToServerPrimary.OnServerEvent:Connect(function(plr, gun)
gun:Clone().Parent = plr.Backpack
end)
rs.WeaponGivingHandlers.ToServer.ToServerSecondary.OnServerEvent:Connect(function(plr, gun)
gun:Clone().Parent = plr.Backpack
end)
rs.WeaponGivingHandlers.ToServer.ToServerMelee.OnServerEvent:Connect(function(plr, gun)
gun:Clone().Parent = plr.Backpack
end)
assigning weapons (client-side):
--weapon containers
local primary
local secondary
local melee
--Getting variables' value
rs.WeaponGivingHandlers.GivePrimary.OnClientEvent:Connect(function(gun) primary = gun end)
rs.WeaponGivingHandlers.GiveSecondary.OnClientEvent:Connect(function(gun) secondary = gun end)
rs.WeaponGivingHandlers.GiveMelee.OnClientEvent:Connect(function(gun) melee = gun end)
local Actionfolder = rs.WeaponGivingHandlers.ToServer
local toserverprimary = Actionfolder.ToServerPrimary
local toserversecondary = Actionfolder.ToServerSecondary
local toservermelee = Actionfolder.ToServerMelee
script.Parent.Play.Frame.Button.MouseButton1Click:Connect(function()
if rs.Booleans.Intermission.Value == false then
if primary then
task.wait(1)
toserverprimary:FireServer(primary)
end
if secondary then
task.wait(1)
toserversecondary:FireServer(secondary)
end
if melee then
task.wait(1)
toservermelee:FireServer(melee)
end
else
print('did not run')
end
end)
delete weapons so player won’t use them in lobby and he could freely change it
--deletes all weapons being in the Backpack when round ends----------------------
local DeleteWeaponsEvent = rs.RewardsEvents.ResetAllRoundTotal
DeleteWeaponsEvent.OnServerEvent:Connect(function(player)
if player.Backpack:GetChildren() then
for i, e in pairs(player.Backpack:GetChildren()) do
e:Destroy()
end
end
end)
If you need more details, please let me know! I’ll be glad for any help provided!