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")'
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.
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.