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

Infinite yield error on ReplicatedStorage:WaitForChild() ?

Asked by 5 years ago

Im trying to make a TextButton that gives a tool named AWP when pressed, these are my scripts

--local script local awpSpawn = game.ReplicatedStorage:WaitForChild("AwpSpawn") script.Parent.MouseButton1Click:Connect(function() game.Players.LocalPlayer.PlayerGui.MainGUI.Guns.Visible = false if script.Parent.Frame.AwpButton.ImageLabel.Visible == true then awpSpawn:FireServer() end end)

--server script

local awpSpawn = Instance.new("RemoteEvent") awpSpawn.Parent = game.ReplicatedStorage awpSpawn.Name = "AwpSpawn" local awpTool = game.ReplicatedStorage.AWP local awpToolClone = awpTool:Clone()

awpSpawn.OnServerEvent:Connect(function(plr) if awpToolClone.Parent ~= plr.Backpack then awpToolClone.Parent = plr.Backpack end end)

then it gives me this error Infinite yield possible on 'ReplicatedStorage:WaitForChild("AwpSpawn")'

0
It's not an error. It's a warning. Try FindFirstChild(). DeceptiveCaster 3761 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

That means it can't find the object AwpSpawn. The reason it is warning you is because it will continue to wait until it becomes available unless you were to override it in the WaitForChild(name, timeInSeconds) like such:

local object = Folder:WaitForChild("Weapon", 20)
-- After 20 seconds it falls back onto nil but
-- but your code continues to execute instead
-- of waiting infinitely.

Adding this will cause it to timeout and continue execution as opposed to endlessly waiting for the object to appear. But you must make sure the rest of your code depending on it can work with nil.

0
Thank you for understanding that it isn't an error. DeceptiveCaster 3761 — 5y
Ad
Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago
local AwpSpawn = game:GetService("ReplicatedStorage"):WaitForChild(“AwpSpawn”)

There are two probable cause of warning. 1. AwpSpawn doesn't exist in ReplicatedStorage. 2. AwpSpawn doesn't exist in ReplicatedStorage yet.

To fix this, you have to make sure that "AwpSpawn" is named "AwpSpawn", Awpspawn or awpSpawn will not work. Also make sure the AwpSpawn is a child of ReplicatedStorage or ReplicatedStorage is the parent of AwpSpawn.

If the problem is not fixed then there is one more thing you can do, that is to increase the time the :WaitForChild() waits for the object to exist. Usually it waits 5 seconds before giving you the warning that infinite yielding is possible. To make the wait time longer do this :

local AwpSpawn = game:GetService("ReplicatedStorage"):WaitForChild(“AwpSpawn”, 20)

Now it will wait 20 seconds.

0
It's not an error. DeceptiveCaster 3761 — 5y
0
oh.. em i was editing it CjayPlyz 643 — 5y
0
still is not working, the name is AwpSpawn and i've tried the timeout RealCoolGuysworld 3 — 5y
0
Can you take a picture of the replicatedstorage, upload it, then edit the question and insert the link there? CjayPlyz 643 — 5y

Answer this question