Hello! I am working on an FPS framework and have had an issue with the error in the title (20:37:05.174 - Infinite yield possible on ‘ReplicatedStorage:WaitForChild(“Left Arm”)’)
I have not been able to find anything very helpful on the DevForum or elsewhere. Please help me out with this.
wait()
until game:IsLoaded()
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local User = game:GetService("UserInputService")
local Run = game:GetService("RunService")
local RS = game.ReplicatedStorage
local GunModules = RS:WaitForChild("GunModules")
local GunModels = RS:WaitForChild("GunModels")
local Primary = "MP40"
local WeaponInHand
local LArm, RArm
local WeaponData
local aimming = false
local maincf = CFrame.new() -- Weapon offset of camera
local larmcf = CFrame.new() -- Left arm offset of weapon
local rarmcf = CFrame.new() -- Right arm offset of weapon
local aimcf = CFrame.new()
User.MouseIconEnabled = false
plr.CameraMode = Enum.CameraMode.LockFirstPerson
Run.RenderStepped:Connect(function()
if WeaponInHand and LArm and RArm then -- check if weapon and arms are loaded
WeaponInHand:SetPrimaryPartCFrame(
cam.CFrame
* maincf
* aimcf
)
LArm:SetPrimaryPartCFrame(
WeaponInHand.PrimaryPart.CFrame
* larmcf
)
RArm:SetPrimaryPartCFrame(
WeaponInHand.PrimaryPart.CFrame
* rarmcf
)
if aimming then
aimcf = aimcf:Lerp(WeaponData.AimCFrame, 0.2) -- Goal CFrame (0.1 is the aim speed)
else
aimcf = aimcf:Lerp(CFrame.new(), 0.1)
end
end
end)
function setup(weapon)
-- Setup weapon data module
WeaponData = require(GunModules:WaitForChild(weapon))
maincf = WeaponData.MainCFrame
-- setup weapons to data module
WeaponData = require(GunModules:WaitForChild(weapon))
maincf = WeaponData.MainCFrame
larmcf = WeaponData.LArmCFrame
rarmcf = WeaponData.RArmCFrame
-- setup arms to camera
LArm = RS:WaitForChild("Left Arm"):Clone()
LArm.PrimaryPart = LArm:WaitForChild("Main")
LArm.Parent = cam
for i, part in pairs(LArm:GetChildren())do
if part:IsA("BasePart") then
part.Anchored = true
part.CanCollide = false
end
end
-- Setup weapn to camera
WeaponInHand = GunModels:WaitForChild(weapon)
WeaponInHand.PrimaryPart = WeaponInHand:WaitForChild("Handle")
WeaponInHand.Parent = cam
for i, part in pairs(WeaponInHand:GetChildren()) do
if part:IsA("BasePart") then
part.Anchored = true -- make all the parts anchored so it wont fall off
part.CanCollide = false -- make all the part non-collidable so you dont fly
end
end
end
mouse.Button2Down:Connect(function()
aimming = true
end)
mouse.Button2Up:Connect(function()
aimming = false
end)
setup(Primary)