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)
COMMUNITY QUESTION
infinite yield on WaitForChild("PlayerStats")?
1 answer
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
also how do i solve this "attempt to index a local player (a nil value)
which line is it
which line is it?
Line 8 (local PlayerUI = Player:WaitForChild("PlayerGui").PlayerUI)