Google Donut
Google Donut

Reputation: 21

"attempted to call require with invalid arguments" How to Fix Roblox Studio Luau

I was making an Egg-Open-Gui for a simulator and when I ran the script it always arrored this:

Attempted to call require with invalid argument(s)

Script Players.Robloxgamer_73738.PlayerGui.Menu.EggScript

the so called "Eggscript" is local

here is my script:

wait(game.Loaded)
wait(5)

local petmodule = require(game:GetService("ServerScriptService"):FindFirstChild("PetModule"))

local cost = script.Parent.Parent.Parent.Cost.Value

local player = game.Players.lo

local openOnceButton = script.Parent.OpenOnce
local autoOpenButton = script.Parent.AutoOpen



openOnceButton.MouseButton1Click:Connect(function()
    
    if player.leaderstats["💸 Money 💸"].Value >= cost then

        player.leaderstats["💸 Money 💸"].Value = (player.leaderstats["💸 Money 💸"].Value - cost)

        local pet = petmodule.chooseRandomPet()

        local petVal = Instance.new("StringValue")
        petVal.Name = pet.Name
        petVal.Parent = player.PetInventory

        game.ReplicatedStorage.HatchEgg:FireServer(pet)

        print(pet.Name.." selected")

    end
    
end)

Upvotes: 1

Views: 1085

Answers (1)

Random
Random

Reputation: 505

You cannot access ServerScriptService in the client. It will be empty, thus, there will be no child. The FindFirstChild call will return nil, which is obviously invalid. Move the module to ReplicatedStorage.

Besides, you don't seem to understand the client-server model. You can't really change a leaderstat value from the client; it will only affect the client and not the server, so other clients will be unaware of the change. You can use RemoteEvents but make sure that you structure them in a way that it will be safe.

Upvotes: 1

Related Questions