I didn’t know what title i could add, well, i have a shop system, and the problem now is that when you buy a pet, everything is normal, but if you click on “Use”, you will still spend money, here is the script:
Client script:
wait(1)
local player = game.Players.LocalPlayer
for i,Buttons in pairs(script.Parent.PetsFrame:GetChildren()) do
local ImageButton = Buttons:FindFirstChild("ImageButton")
print("a")
if ImageButton then
ImageButton.MouseButton1Down:connect(function()
local HasBought = Buttons:FindFirstChild("HasBought")
print("a1")
if HasBought then
if HasBought.Value == true then
game.ReplicatedStorage.PetAdd:FireServer(Buttons.Name)
else
local Cost = Buttons:FindFirstChild("Cost")
if Cost then
print("a2")
local leaderstats = player:FindFirstChild("NOOOOOOB")
if leaderstats then
local Cash = leaderstats:FindFirstChild("Cash")
if Cash then
print("a3")
if Cash.Value >= Cost.Value then
HasBought.Value = true
game.ReplicatedStorage.PetAdd:FireServer(Buttons.Name)
print("a4")
end
end
end
end
end
end
end)
end
print("end)
end
print("Done")
Server Script:
local Rep = game:GetService("ReplicatedStorage")
local event = Rep:FindFirstChild("PetAdd")
event.OnServerEvent:Connect(function(plr, object)
if not prices[object] then return end
-- car with that name doesn't exist
if plr.NOOOOOOB.Cash.Value >= prices[object] then
plr.NOOOOOOB.Cash.Value = plr.NOOOOOOB.Cash.Value - prices[object]
-- give them their prized posession
local Pet = plr:FindFirstChild("Pet") --Finds value of the player
if Pet then
Pet.Value = object
local Char = game.Workspace:FindFirstChild(plr.Name)
if Char then
for i,clearchild in pairs(Char:GetChildren()) do
if clearchild.Name == "Pet" then
clearchild:Destroy()
end --we should print("e")
end
local UpperTorso = Char:FindFirstChild("UpperTorso")
if UpperTorso then
for i,clearweld in pairs(UpperTorso:GetChildren()) do
if clearweld.Name == "PetWeld" then
clearweld:Destroy()
end
end
local PetPart = game.Lighting.Pets:FindFirstChild(object)
if PetPart then
local PetWeld = Instance.new("Weld",UpperTorso)
PetWeld.Name = "PetWeld"
PetWeld.C0 = CFrame.new(3,1,0)
PetWeld.Part0 = UpperTorso
local NewPet = PetPart:Clone()
NewPet.Parent = Char
NewPet.Name = "Pet"
PetWeld.Part1 = NewPet
NewPet.Anchored = false
NewPet.CanCollide = false
local OwnedPets = plr:FindFirstChild("OwnedPets")
if OwnedPets then
local Findif = OwnedPets:FindFirstChild(object)
if Findif then
else
local newitem = Instance.new("Folder",OwnedPets)
newitem.Name = object
end
end
end
end
end
end
end
end)
Could you help me? Thanks if you do