Roblox Player Folder Not Being Able To Be Accessed By The Client?

I want to make a simple purchase script to buy an item which has datastore.

Issue is when I attempt a purchase, the client shows the frustrating “Infinite Yield Against(“ObjectName”)”

I tried almost everything, and if I missed something in the dev forum, please tell me where I can find it.

Here is my code!

CLIENT:

script.Parent.MouseButton1Click:Connect(function()
	local player = game:GetService("Players").LocalPlayer
	local leaderstats = player:WaitForChild("leaderstats")
	local grass = leaderstats:WaitForChild("Grass")
	local mower = player:WaitForChild("MowerStorage"):WaitForChild("Mower5") -- Make sure this is the actual instance

	if grass.Value >= 125000 then
		game:GetService("ReplicatedStorage").BuyRemote:FireServer(125000, mower)
	end
end)

SERVER:

game:GetService("ReplicatedStorage"):WaitForChild("BuyRemote").OnServerEvent:Connect(function(player, amount, mower)
	local leaderstats = player:FindFirstChild("leaderstats")
	local grass = leaderstats and leaderstats:FindFirstChild("Grass")

	if grass and typeof(amount) == "number" and grass.Value >= amount and mower and mower:IsA("BoolValue") then
		grass.Value -= amount
		mower.Value = true
	else
		
	end
end)

So the script can’t find MowerStorage from the player.

Is the folder inside of the player when you test it in-game?

Yes it is inside the player when i join the game.

Show me an image of the explorer under the player in-game. And on which line does yield infinitely?

you don’t need to call the mower into the remoteevent, you can call it by using this code in the server:

local mower = player.MowerStorage.Mower5

I’m sorry to bring up something other than the problem you are having, but there is a huge security flaw in your code.

Anything you do in a local script can also be done by cheaters. So when you make the local script send over the price they have to pay through the remote, cheaters can just set that to whatever they want.

If a cheater were to play your game right now, they could easily get all mowers for free, as well as give themselves infinite money.

You need to make sure that you handle the price of mowers on the server, not the client.

3 Likes

but does your code work even though it shows infinite yield? If your code works and you just want to silence it then just do :WaitForChild("", math.huge) (idk if i understood your issue)

Are you sure the Folder name is MowerStorage?

Make sure the names are actually spelled right, Lua is very case sensitivite so make sure the caps are right too, for example, is “leaderstats” actually spelled that and not “LeaderStats”?.

The second thing i would say is, are you confident it exists? Print out the object before actually waiting for the child.

Thirdly this may be irrelevant but are the folders being created by the client instead of the server? I dont think this is the case but anything the client makes, will not be seen and acknowledge by the server.

Quick note. What @stef0206 said is correct, you are also facing security problems. Never trust the client about important data.