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.
