简体   繁体   中英

Are you able to add code for other text buttons with a local script inside somewhere else in Luau?

So im making a cookie clicker made with gui in Luau and im trying to make it so when you click a button it takes cookies away and adds a multiplyer, but the script is inside the cookie button

local cookies = 0
local plr = game.Players.LocalPlayer
local clickMultiplyer = 1

script.Parent.MouseButton1Click:Connect(function()
    cookies = cookies + cm
    plr.PlayerGui.CookiesDisplayText.Text = cookies
end

--This first part works just fine--

plr.PlayerGui.ShopUi.BuyButton:Connect(function()
    if cookies == 100 or cookies =< 100 then
        cookies = cookies - 100
        cm = cm + 1
    else
        plr.PlayerGui.ShopUi.BuyButton.Text = "not enough cash"
        wait(.5)
        plr.PlayerGui.ShopUi.BuyButton.Text = "Buy cost:100 +1 clickmultiplyer"
    end
end

Theres no errors but it simply does not work, thank you in advance:))

I fixed all errors that vs code and roblox detected.

It's spelled "multiplier". You have two variables for the same thing. This should work, assuming everything else is set up properly.

local cookies = 0
local plr = game.Players.LocalPlayer
local multiplier = 1

script.Parent.MouseButton1Click:Connect(function()
    cookies += multiplier
    -- This may cause issues, a TextLabel inside of PlayerGui should not be visible unless it's parented to a ScreenGui
    plr.PlayerGui.CookiesDisplayText.Text = cookies
end

plr.PlayerGui.ShopUi.BuyButton:Connect(function()
    if cookies >= 100 then
        cookies -= 100
        cm += 1
    else
        plr.PlayerGui.ShopUi.BuyButton.Text = "not enough cash"
        task.wait(.5)
        plr.PlayerGui.ShopUi.BuyButton.Text = "Buy cost:100 +1 clickmultiplier"
    end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM