im making a gun loadout system and im almost done but im having issues on getting gun StringValue from the player and giving the player the weapon. heres the code
local ReplicatedStorage = game.ReplicatedStorage
local PrimaryFolder = ReplicatedStorage.Weapons.Primary
function module.Test(player)
local primaryweapon = PrimaryFolder:FirstFindChild(player.EquippedPrimary.Value)
primaryweapon.Parent = player.Character
print(primaryweapon)
end
return module
It’s likely something to do with how you’re giving it the player or how you’re trying to get the Value, is this function being ran immediately when the client joins?
local module = require(script.ModuleScript)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local players = {}
for i, v in pairs(game.Players:GetPlayers()) do
table.insert(players,v)
end
module.Test(players)
end)
end)
That’s the issue then, you’re not giving it time for EquippedPrimary to exist. Try replacing your .Test function with this
function module.Test(player)
local equipped = player:WaitForChild("EquippedPrimary")
local primaryweapon = PrimaryFolder:FirstFindChild(equipped.Value)
primaryweapon.Parent = player.Character
print(primaryweapon)
end
Wait wait, in this function it works if you give it a signle player, but you’re giving it a table of players?
The function you made works if you give it a single palyer, but you’re giving it a table of players, that’s why it’s erroring, the function was not made to handle a table of players
function module.Test(players)
for _,player in pairs(players) do
local equipped = player:WaitForChild("EquippedPrimary")
local primaryweapon = PrimaryFolder:FirstFindChild(equipped.Value)
primaryweapon.Parent = player.Character
print(primaryweapon)
end
end
Or you can keep it the same and instead of returning a list of players, just put it in that in pairs loop you have and give it the player
Do you actually define module at the top of the script?
local module = {}
local ReplicatedStorage = game.ReplicatedStorage
local PrimaryFolder = ReplicatedStorage.Weapons.Primary
function module.Test(player)
local primaryweapon = PrimaryFolder:FirstFindChild(player.EquippedPrimary.Value)
primaryweapon.Parent = player.Character
print(primaryweapon)
end
return module
Also when you do module.Test(players), it uses a set of players and not just one player.