My script gets the pets and creates (Clone) a frame for each Pet.
The issue is that instead of cloning the frame once, it duplicates twice. I don’t know how to solve it, here is the script:
local Lighting = game:GetService("Lighting")
local ShopItems = Lighting.Pets
local player = script.Parent.Parent.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopData = require(ReplicatedStorage.ShopData)
local PetsData = ShopData["Pets"]
local PrefabItem = ReplicatedStorage.ShopStuff:FindFirstChild("SlotLayout")
local Frame = script.Parent.PetsFrame
for _, Pet in pairs(ShopItems:GetChildren()) do --//Find pets
local Item = PrefabItem:Clone() --//Duplicate
if (PetsData[Pet.Name]) then
local PetData = (PetsData[Pet.Name])
Item.Parent = Frame
Item.Name = Pet.Name
Item.Info.Text = PetData["Info"]
Item.Cost.Value = PetData["Cost"]
Item.ImageShow.Image = "rbxassetid://" .. PetData["ImageId"]
wait(0.2)
end
print(Pet)
end
This could be because you have two of the same pet names. If that isn’t the case you could try putting a break somewhere in it and see if that fixes the problem.
What does Break does? I thought it was something unnecessary…
And also, this is a Script, not a LocalScript, this error started when i used Script instead of Local, since the server can get the information about the “petdata” in the client-sided script.
Dont know if this fixes your problem, but consider moving PrefabItem:Clone() after your If statement because otherwise when (PetsData[Pet.Name]) is not true it would unnecessarily create frames.
for _, Pet in pairs(ShopItems:GetChildren()) do --//Find pets
local Item = PrefabItem:Clone() --//Duplicate
if (PetsData[Pet.Name]) then
if not Frame:FindFirstChild(PetsData[PetName]) then
local PetData = (PetsData[Pet.Name])
Item.Parent = Frame
Item.Name = Pet.Name
Item.Info.Text = PetData["Info"]
Item.Cost.Value = PetData["Cost"]
Item.Name = PetData[Pet.Name]
Item.ImageShow.Image = "rbxassetid://" .. PetData["ImageId"]
wait(0.2)
end
By any reason, now the player doesn’t get the pet. How do i solve this?
If you need the script which sends the event, i can give it:
local player = game.Players.LocalPlayer
for i,Buttons in pairs(script.Parent.PetsFrame:GetChildren()) do
local ImageButton = Buttons:FindFirstChild("ImageButton")
if ImageButton then
ImageButton.MouseButton1Down:connect(function()
local HasBought = Buttons:FindFirstChild("HasBought")
game.ReplicatedStorage.PetAdd:FireServer(Buttons.Name)
print(player.Name.." sent a request to the server to buy something!")
end)
end
end
@ignacasas06im going to cry if u dont respond me :d