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

Is there a better way to wait for a boolean value to properly load in this script? [closed]

Asked by
noew -5
6 years ago

I have this block of code that checks if a value from the DataStoreService is true, and then gives the player an item.

local torch = game.ServerStorage.Torch

local function onAdd(Player)
    Player.CharacterAdded:connect(function()
    local data = Player:WaitForChild("data")
    if data then
        print("Data folder located")
        local hasTorch = data:WaitForChild("hasTorch")
        if hasTorch then
            print("hasTorch found")
            wait(5)
            if hasTorch.Value then
                local newTorch = torch:Clone()
                newTorch.Parent = Player.Backpack
            else
                warn("hasTorch failed")
            end
        end
    end
    end)
end

game.Players.PlayerAdded:Connect(onAdd) 

Is there a better way to wait for hasTorch to have a value? Without the wait it returns the warn statement and ends there.

Closed as Primarily Opinion-Based by User#19524

This question has been closed because it is a discussion about a topic focused on diverse opinions, which isn't a good fit for our Q&A format.

Why was this question closed?