Hey Forumers, I’ve been making a simulator game, which has pets that you can hatch. Well, I made a command that makes it so i can give pets simply by typing the command in the chat. It worked and all when i was using the pet name to determine which pet to give, so i then tried to make it so that if the player types the command, but instead of the pet’s name it used the pet Id which is determined under a module script, but its not working for some reasons. this is my current givePet script:
--[ Library ]--
local _R = nil
local RunService = game:GetService("RunService")
if RunService:IsServer() then
_R = require(game:GetService("ServerStorage"):WaitForChild("RobloxianFramework"))
else
_R = require(game:GetService("ReplicatedStorage"):WaitForChild("RobloxianFramework"))
end
while not _R.Loaded do
game:GetService("RunService").Heartbeat:Wait();
end;
local wait = _R.AccurateWait
--[ Script ]--
return {
Name = "GivePet",
MinimumRank = "Owner", -- Minimum rank of 2 for this command
Usages = {"pet"},
ParamFormat = {"Player", "Number", "Number"},
Callback = function(executor, players, PetId, Power)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PetsFolder = ReplicatedStorage:WaitForChild("Pets")
local foundPetData = nil
-- Iterate through each pet folder to find the correct PetId
for _, petFolder in pairs(PetsFolder:GetChildren()) do
print("Checking folder: " .. petFolder.Name)
if petFolder:IsA("Folder") then
local petModuleScript = petFolder:FindFirstChild("PetData")
if petModuleScript then
print("Found module script in folder: " .. petFolder.Name)
local petData = require(petModuleScript)
print("Pet Id from module script: " .. tostring(petData.PetId))
print("Pet Id provided: " .. tostring(PetId))
if petData.PetId == PetId then
foundPetData = petData
break
end
else
warn("Module script not found in folder: " .. petFolder.Name)
end
end
end
if foundPetData then
print("Creating pet with PetId: " .. tostring(foundPetData.PetId))
for _, plr in pairs(players) do
task.spawn(function()
local success, errorMessage = pcall(function()
_R.Pets.create(plr, foundPetData.PetId, "Normal", Power)
end)
if not success then
warn("Error creating pet: " .. errorMessage)
end
end)
end
return true
else
warn("Pet module not found for PetId: " .. tostring(PetId))
return false
end
end
}
it should be working, since all the prints are being printed properly, except the ones in the foundPetData block.
If you’re wondering, this is my module script in the pets that determines the petId:
local PetData = {
PetName = "4 Eyes",
PetId = "1",
Rarity = "Secret",
PetArea = "Area : 🏙️Spawn",
Models = {},
Huge = false,
MinPower = 69,
MaxPower = 6969,
RecordPetExist = true,
Mode = "Hover", --Walk/Hover
HideCollection = {
Normal = true,
Amethyst = true,
E = true,
Rainbow = true
},
}
return PetData
any help is highly generous