Im Trying To Make a Pet System, But Am Having an Error on Code that is "Correct"

Im Currently Trying to Achieve Alvin Blox’s Pet Hatching Tutorial But Im Having an Error on the Click Detector Script.
Im Having an Error Whenever I join the game and press the Click Detector. It takes Cash from the player, But in the output it’s supposed to say The Name of the Pet Then Selected so say I have a dog it would be “Dog Selected” The Error says " Workspace.Model.Text.Script:11: attempt to call a nil value"
Some Solutions I have tried are Rewriting The Code Multiple Times, Looking Up The error, and So Fra None of These have worked.
Below Is the Code, I Also will have the Video Linked, Any Feedback, or Help Would Be Amazing!

local cost = 500

local petModule = require(game.ServerScriptService:WaitForChild("PetModule"))

script.Parent.ClickDetector.MouseClick:Connect(function(player)

	if player.leaderstats.Cash.Value >= cost then

		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost

		local pet = petModule.chooseRandomPet()

		print(pet.Name.." selected")

	end

end)

Thank You For Any Help!

1 Like

Line 11 (local pet = petModule.chooseRandomPet()" is where my error is

3 Likes

Does the PetModule have a function named “chooseRandomPet”?
make sure you haven’t made any typos.

2 Likes

replace

if player.leaderstats.Cash.Value >= cost then

with

if (player.leaderstats.Cash.Value >= cost) then

2 Likes

Just Tested This, and I Still Have an Error

1 Like

In The Tutorial A Function Was Never Made for “chooseRandomPet”

1 Like

The creator makes the function on minute 14:38.

2 Likes

Alright Ill Check it out. Is It The Module Script?

1 Like

Yes, please watch the entire video without skipping any parts.

1 Like

Rewatching That Part I Did Indeed Make The Function

1 Like

Can you show us the function’s code?

1 Like

Went Through Code Again, and You Helped Thank You.

2 Likes