-
What do you want to achieve?
I’m trying to make an egg hatching system -
What is the issue?
Whenever the player presses E, it returns a string value instead of the selectedEgg and i’ve no idea how to fix it. -
What solutions have you tried so far?
I’ve tried typing the error on the dev forum and almost nothing came out.
This is the function in the local script (the error is on the same line as “for _, pet in hatch do”:
local function Hatch(hatchAmount) -- universal function to hatch eggs
print("5") -- prints
if selectedEgg then
local timeValue = player.leaderstats.Time.Value
local price = eggs:FindFirstChild(selectedEgg):GetAttribute("Price") * hatchAmount -- gets the price of the egg * the hatch amount
local afford = timeValue >= price -- if player time is lower than the price then afford = false if it's higher then it's equal to true
print("6") -- print
if afford then
local hatch = hatchPets:InvokeServer(selectedEgg)
if hatch then
for _, pet in hatch do -- this is where the error is
hatchAnim(selectedEgg, pet)
print("7") -- doesn't print
end
end
end
end
end
This is the server side, where the remote function is triggered:
local function choosePet(selectedEgg)
local chance = math.random(1, totalWeight)
local counter = 0
for _, pet in pairs(pets:FindFirstChild(selectedEgg):GetChildren()) do
counter += pet:GetAttribute("Rarity")
if chance <= counter then
return pet.Name
end
end
end
hatchPets.OnServerInvoke = function(player, selectedEgg)
totalWeight = 0
for _, pet in pairs(pets:FindFirstChild(selectedEgg):GetChildren()) do
totalWeight += pet:GetAttribute("Rarity") -- the total rarity doesn't need to be at exactly 100%, if it's at 99.1%, it's still good.
end
local chosenPet = choosePet(selectedEgg)
return chosenPet
end
Would be really appreciated if anyone could help. Thanks in advance