for i,v in pairs(script.Parent.Essentials:GetChildren()) do
local Owner = script.Parent.Owner
if v.Name == "PartCollector" then
v.Touched:connect(function(Part)
if Part:FindFirstChild('Cash') then
if Owner.Value ~= nil then
local player = game.Players:WaitForChild(Owner.Value)
local gamepasses = player:WaitForChild("Gamepasses")
if gamepasses["Auto Collect Cash"].Value == true then
local playerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
if playerMoney ~= nil then
playerMoney.Value = playerMoney.Value + (Part.Cash.Value * gamepasses.Cash.Value)
end
elseif gamepasses["Auto Collect Cash"].Value == false then
Money.Value = Money.Value + (Part.Cash.Value * gamepasses.Cash.Value)
Debris:AddItem(Part,0.1)
end
end
end
end)
end
end
And I get this in the output:
22:56:03.939 - Infinite yield possible on ‘Players:WaitForChild(“Instance”)’
22:56:03.940 - Stack Begin
22:56:03.941 - Script ‘Workspace.Zednov’s Tycoon Kit.Tycoons.Brownie.PurchaseHandlerNew’, Line 36
22:56:03.942 - Stack End
Line 36 is here:
local player = game.Players:WaitForChild(Owner.Value)
Why is this happening? Also, here is a picture of the explorer/properties
It is merely a warning that it may not ever find Owner.Value. Warnings appear orange and they do not indicate that your script will not run. An error appears red and tells you that your code will not run or ended abruptly.
If Owner.Value is a player, you can just refer to it directly: local player = Owner.Value
Otherwise, if Owner.Value is a string, then you are fine so long as Owner.Value is set correctly prior to using WaitForChild. If Owner.Value is an Instance, you need to use Owner.Value.Name. If Owner.Value is going to be updated while waiting, you can run this instead. while not game.Players:WaitForChild(Owner.Value) do wait(1) end
Note that the warning will probably not go away, these are just some things to double-check. Lua is not very powerful as far as detecting things that will go wrong later, and it really shines here.
This is a common error. To solve this just put a comma and a number next to the “Instance”. E.g.
Players:WaitForChild("Instance",5)
The number just means the time in seconds the system will keep checking for that child. When the time ends the system will stop checking. Infinite yield possible just means that the system will keep checking until it finds the child and can go on forever.
I tried local player = Owner.Value and the warning did not come up again. Now the only problem is that when the collecter collects the drops, the money to collect does not go up…
You can’t wait on an instance value, it should be like this:
local player = game.Players:WaitForChild("Owner").Value
To sum up, first you need the quotations around the name of the variable. The other thing is that Owner.Value is not an instance. The .Value part is a property of it, thus it won’t exist if you look for it in the workspace.
Edit:
Building on what the others above have said, you don’t need to worry about waiting for “Owner” to exist. Since you are running it off of an event that is likely to take place after everything is loaded in the game, it’s safe to use local player = Owner.Value instead. Calling WaitForChild will just add more latency in the script.