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

infinite yield on WaitForChild("PlayerStats")?

Asked by 5 years ago
Edited 5 years ago
local tool = script.Parent

local Settings = tool:WaitForChild("Settings")
local Strength = Settings:WaitForChild("Strength")

local Player = game.Players.LocalPlayer:WaitForChild("PlayerStats")
local PlayerUI = Player:WaitForChild("PlayerGui").PlayerUI

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local CoinClicked = RemoteEvents.CoinClicked

local Debounce = false

tool.Activated:Connect(function()
    if Player.PlayerStats.CurrentValue.Value < Player.PlayerStats.Storage.Value then
        if Debounce == false then
        Debounce = true
        CoinClicked:FireServer(Strength.Value)
        wait(0.20)
        Debounce = false
        end
 else
        if PlayerUI.StorageFull.Visible == false then
            if Debounce == false then
                Debounce = true
                PlayerUI.StorageFull.Visible = true
                wait(0.5)
                Debounce = false
            end
        end
    end
end)


1 answer

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

Don't worry, infinite yields arent a problem, it's just your script, it is stuck on that line and always trying infinitly to find the given child which is not loaded yet or might not be a thing at all. To prevent this you can use WaitForChild's second argument, which the wait time, and it'll probarly remove the yielding.

local Player = game.Players.LocalPlayer:WaitForChild("PlayerStats", 1)
--1 is just an example put whatever you want

0
also how do i solve this "attempt to index a local player (a nil value) Narrowlegobricks 12 — 5y
0
which line is it starmaq 1290 — 5y
0
which line is it? starmaq 1290 — 5y
0
Line 8 (local PlayerUI = Player:WaitForChild("PlayerGui").PlayerUI) Narrowlegobricks 12 — 5y
Ad

Answer this question