#why doesnt it work??

1 messages · Page 1 of 1 (latest)

torpid spear
#

ive spent 1 hour idk bro

local sound = Instance.new("Sound")
local isActive = false
local player = game.Workspace:WaitForChild("bgoku0710")
local luckLabel = player.PlayerGui.ScreenGui.luck
local clover = game.Workspace.clover
local cloverTouched = false

local luckBuffs = {}

local function updateLuck()
    local total = 0
    for _, value in pairs(luckBuffs) do
        total = total + value
    end
    luckLabel.Text = "Luck: " .. total
end

local function addLuck(name, value)
    luckBuffs[name] = value
    updateLuck()
end

local function removeLuck(name)
    luckBuffs[name] = nil
    updateLuck()
end

tool.Equipped:Connect(function()
    isActive = true
    sound.Parent = script.Parent
    sound.SoundId = "rbxassetid://81733232182014"
    sound:Play()
end)

tool.Unequipped:Connect(function()
    isActive = false
    sound.Parent = script.Parent
    sound.SoundId = "rbxassetid://6653567310"
    sound:Play()
    removeLuck("gear")
end)

if clover then
    clover.Touched:Connect(function(otherPart)
        if not cloverTouched then
            cloverTouched = true
            game.Debris:AddItem(clover, 0.1)
            addLuck("clover", 0.5)
        end
    end)
end```
hushed hawk
winged flax
#

local luckLabel = player.PlayerGui.ScreenGui.luck
This will error if:

ScreenGui doesn't exist

luck label doesn't exist

This code runs before PlayerGui is ready (e.g. script ran before the UI was fully loaded)

#

isntead do: local luckLabel = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("luck")

#

and also