I am attempting with making a L4D like weapon pickup system with my game. I have achieved porting weapons into player’s camera and weapon switching so far.
I have tried many methods, searched for hours on varied forums, yet neither found any satisfactory solution nor a fitting topic about it.
Here is my code:
local replicatedStorage = game:GetService('ReplicatedStorage')
local UIS = game:GetService('UserInputService')
local loadoutUpdate = replicatedStorage.Events:WaitForChild('LoadoutUpdate')
local primary
local secondary = 'Glock17'
local weaponInHand
loadoutUpdate.OnClientEvent:Connect(function(backpack)
if primary ~= backpack[1] then
primary = backpack[1]
setup(primary)
elseif secondary ~= backpack[2] then
secondary = backpack[2]
setup(secondary)
end
end)
function setup(weapon)
if weapon ~= nil then
print(weapon)
weaponInHand = replicatedStorage.Weapons:WaitForChild(weapon)
print("Now equipping: ", weaponInHand)
end
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.One then
setup(primary)
elseif input.KeyCode == Enum.KeyCode.Two then
setup(secondary)
end
end)
setup(primary)
When a new gun is picked up, the Primary and Secondary variable work fine as the ‘weapon’ variable shows the name of the current weapon, but the game cannot find the script/model with the exact name no matter if model I’m trying to reach has been already inside ReplicatedStorage. This is what I always get in return:
Can someone help me finding a solution, or at least, a hint for this? Thanks for all of your suggestions.