Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Egg hatch gui button doesnt hatch the egg when pressed. what am i missing?

Asked by 2 years ago
Edited 2 years ago

basically I have a confirm message that says yes or no. i want it so when you click Yes, it plays the hatch anim. i thought this script would work but apparently not.. Am i missing something? here's the code:

local RS = game:GetService("ReplicatedStorage")
local Eggs = require(RS:WaitForChild("Eggs"))
local Data = Eggs[script.Name]
local Cost = Data["Cost"]
local Pets = Data["Pets"]


local Buy = game.StarterGui.Message.Frame
local CD = Buy.Yes
local CostGUI = Buy
local CostText = CostGUI:WaitForChild("Cost")

CostText.Text = Cost.." Coins?"

local TotalWeight = 0
for i,v in pairs(Pets) do
    TotalWeight = TotalWeight + v[1]
end

local function ChoosePet()
    local Chance = math.random(1,TotalWeight)
    local Counter = 0
    for i,v in pairs(Pets) do
        Counter = Counter+v[1]
        if Chance <= Counter then
            return i
        end
    end
end

CD.MouseButton1Click:Connect(function(Player)
    local Stats = Player:WaitForChild("leaderstats")
    local Coins = Stats:WaitForChild("Coins")
    local open = Player:WaitForChild('OpenValue')
    local got = Player:WaitForChild('GotPet')
    if Coins.Value >= Cost then
        Coins.Value = Coins.Value - Cost
    open.Value = 'Open'
    got.Value = ChoosePet()
    local findpet = Player:WaitForChild('Pets')
    local sqq = findpet:FindFirstChild(got.Value)
     sqq.Value = 'owned'
        wait(5)
    open.Value = 'Close'
    got.Value = ''
    end
end)

1 answer

Log in to vote
0
Answered by
extrorobo 104
2 years ago

I think I have an answer. it will not be the perfect answer, meaning that i will just post a pic of the exact script, but i do have a few things to add, that will help your code work. First of all, I think that you may need to use if than else, and then. for example you want it to say yes right? so then say something like " if click yes, then play hatch anim" if you write something like that on your code, it will work, because the computer needs to know what it has to do if you click yes. you dont have to redo your entire code, but i reccomend you to read your entire code and add a few if then elses where needed. I really hope this helped. if you need anything else please friends request me on roblox.

Ad

Answer this question