Hello everyone! I am trying to make gun game randomize weapons, however when I went to test, I encountered an error: Only one player was getting a gun?
I have my code sample here of the script, and am willing to provide any function calls necessary!
function GivePlayerEquipment(player)
-- Check which equipment to give to player
local equipmentIndex = math.random(1, EQUIPMENT_COUNT)
if equipmentIndex > EQUIPMENT_COUNT then
equipmentIndex = EQUIPMENT_COUNT
end
local equipmentToSpawn = EQUIPMENT_LIST:GetChildren()[equipmentIndex]:GetCustomProperty("Equipment")
if not equipmentToSpawn then return end
-- Spawn and equip the weapon to the player
equipment[player] = World.SpawnAsset(equipmentToSpawn)
assert(equipment[player]:IsA("Equipment"))
equipment[player]:Equip(player)
Events.BroadcastToPlayer(player, "BannerMessage", "Equipped "..equipment[player].name)
end
Would you please provide the code block from which the GivePlayerEquipment was called. So far the function seems to be fine; I'm thinking the error lies in the context from which GivePlayerEquipment was called.
If you set the equipment index to 1 (as opposed to math.random(1, EQUIPMENT_COUNT) ) will all players receive a weapon (I'm thinking that some of the equipment indexes lead to empty equipment). Also, is this script networked or running in a server context?
I'm thinking that only one of the items in the equipment list is valid, to test this I recommend setting the equipmentIndex to a fixed number as opposed to a random number.