Egg Hunt Tool Reward Help

I currently have an egg hunting system and when the player collected all eggs, they receive 75K points in their leaderstats, but I also want them to receive a sword.

Can anyone please help?

It would probably be for the best if you showed the code - We cannot help you from just a screenshot of some eggs in a field.

You could make something like:

-- Create a table to store all the eggs in the game world
local Eggs = {} -- Insert your table with all eggs here

-- Loop through each egg in the Eggs table
for _, egg in pairs(Eggs) do
  -- Set up a connection for when a player touches an egg
  egg.Touched:Connect(function(hit)
    local Player = Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
        -- Retrieve the current amount of eggs collected by the player or default to 0
        local Amount = hit:GetAttribute("EggsCollected") or 0
        -- Increment the amount of collected eggs by 1 and update the player's attribute
        hit:SetAttribute("EggsCollected", Amount + 1)
        -- Destroy the collected egg in the game world
        egg:Destroy()
	end
  end)
end

Now you can track the amount of eggs the player already collected with the attribute inside the player, you can make a function to check when the amount of eggs collected is equal to 10:

-- Set up a connection for when a player's attribute changes
hit.AttributeChanged:Connect(function(attribute)
  -- Check if the changed attribute is "EggsCollected"
  if attribute == "EggsCollected" then
    -- Retrieve the current amount of eggs collected by the player or default to 0
    local Amount = hit:GetAttribute("EggsCollected") or 0

    -- Check if the player has collected 10 eggs
    if Amount == 10 then
      -- Clone a sword from the server storage (adjust the path accordingly)
      local Sword = game.ServerStorage.Sword:Clone()
      
      -- Parent the cloned sword to the player's backpack
      Sword.Parent = hit.Backpack

      -- You can adapt here you code so you can give the money to the player that collected all eggs
    end
  end
end)

I want to point out that you have to adapt the code to work with your game; the code I provided is just an idea of what you would need to do.

1 Like

I don’t really script or anything, so I apologise if this makes it hard for you, but please tell me where to place the script and what type of script.

FYI, you are not meant to ask for entire systems on the devfourm, only help from an existing one (aka, we can’t do all the work for you)

My bad then. Thanks for the reminder though.