So im trying to make a game similar to Pet Simulator X but with Missiles, and i tried making a chest opening system but the error pops out on line 51.
the error:
Argument 1 missing or nil - Client - ChestsClient:51
Stack Begin - Studio
Script 'Players.UGA_BUGAGG.PlayerScripts.ChestsClient', Line 51 - function hatchChest -
Studio - ChestsClient:51
Stack End - Studio
the script:
local runService = game:GetService("RunService") local replicatedStorage = game:GetService("ReplicatedStorage") local players = game:GetService("Players") local tweenService = game:GetService("TweenService") local chests = workspace:WaitForChild("MainFolder_Workspace"):WaitForChild("Chests") local remotes = replicatedStorage:WaitForChild("Remotes") local pets = replicatedStorage:WaitForChild("Pets") local player = players.LocalPlayer local chestSystemSS = player:WaitForChild("PlayerGui"):WaitForChild("ChestSystem") local chestViewport = chestSystemSS:WaitForChild("ChestViewport") local function hatchChest(chestName, chosenPet) for _, v in pairs(player.PlayerGui:GetChildren()) do if v:IsA("ScreenGui") and v ~= chestSystemSS then v.Enabled = false end end chestSystemSS.Enabled = true for _, v in pairs(chestViewport:GetChildren()) do if v:IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then v:Destroy() end end chestViewport.Size = UDim2.fromScale(0, 0) local chestMesh = chests:FindFirstChild(chestName):Clone() chestMesh.Parent = chestViewport chestMesh.CFrame = CFrame.new(0, 0, 0) local camera = Instance.new("Camera") camera.Parent = chestViewport camera.CFrame = CFrame.new(0, 0, 4) chestViewport.CurrentCamera = camera tweenService:Create(chestViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.604, 0,0.785, 0)}):Play() task.wait(0.7) for i = 1, 4 do tweenService:Create(chestViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 20}):Play() task.wait(0.3) tweenService:Create(chestViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = -20}):Play() task.wait(0.3) end tweenService:Create(chestViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 0}):Play() task.wait(0.3) tweenService:Create(chestViewport, TweenInfo.new(0.7), {Size = UDim2.fromScale(0, 0)}):Play() task.wait (0.3) for _, v in pairs(chestViewport:GetChildren()) do if v:IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then v:Destroy() end end local petModel = pets:FindFirstChild(chosenPet.PetName):Clone() petModel:PivotTo(CFrame.new(0, 0, 0)) petModel.Parent = chestViewport local cameraPet = Instance.new("Camera") cameraPet.Parent = chestViewport cameraPet.CFrame = CFrame.new(0, 0, -3.3) * CFrame.Angles(0, math.rad(180), 0) chestViewport.CurrentCamera = cameraPet tweenService:Create(chestViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.27, 0,0.375, 0)}):Play() chestViewport.NameLabel.Text = chosenPet.PetName chestViewport.NameLabel.Visible = true chestViewport.RarityLabel.Text = chosenPet.Rarity chestViewport.RarityLabel.Visible = true task.wait (1.5) tweenService:Create(chestViewport, TweenInfo.new(0.3), {Size = UDim2.fromScale(0, 0)}):Play() task.wait (0.3) chestViewport.NameLabel.Visible = false chestViewport.RarityLabel.Visible = false for _, v in pairs(script.Parent:GetChildren()) do if v:IsA("ScreenGui") and v ~= chestSystemSS then v.Enabled = true end end end remotes:WaitForChild("HatchChest").OnClientEvent:Connect(hatchChest)
I believe that the chosenPet arguement you are passing has failed previously in your script, like Leamir.
You might also want to consider cloning objects on the Server Side rather than in a Local Script on the Client. This may be contributing to your issue, perhaps?