Code:
repeat
wait()
until game:IsLoaded()
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local rs = game.ReplicatedStorage
local gunModules = rs:WaitForChild("GunModules")
local gunModels = rs:WaitForChild("GunModels")
local primary = "M16"
local weaponInHand
local weaponData
local maincf = CFrame.new()
plr.CameraMode = Enum.CameraMode.LockFirstPerson
run.RenderStepped:Connect(function()
if weaponInHand then
weaponInHand:SetPrimaryPartCFrame(
cam.CFrame
* maincf
)
end
end)
function setup(weapon)
weaponData = require(gunModules:WaitForChild(weapon)) -- error is here
maincf = weaponData.MainCFrame
weaponInHand = gunModels:WaitForChild(weapon)
weaponInHand.PrimaryPart = weaponInHand:WaitForChild("Handle")
weaponInHand.Parent = cam
for i,v in pairs(weaponInHand:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
v.CanCollide = false
end
end
end
setup(primary)
Hierarchy of replicated storage:
What am I doing wrong?