Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"Argument 1 missing or nil" i dont know how to fix it, can someone help me?

Asked by 1 year ago
Edited 1 year ago

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)
0
You are passing nil on the chosenPet argument, or it doesn't have the property PetName Leamir 3138 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

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?

0
so i have to clone something? i just followed a tutorial on youtube but it doesn't work as you can see. UGA_BUGAGG 0 — 1y
0
Yes, you're script is cloning an 'Instance' fo KarateKid147 4 — 1y
0
what should i clone UGA_BUGAGG 0 — 1y
0
Sorry let me explain more clearly. Your script does :Clone() two or three times. This should be done on a script not a local script KarateKid147 4 — 1y
Ad

Answer this question