For loop not changing the value of my value

I am trying to make this script give a player a plot for them to build on, but it won’t set the owners value. I have been looking through this code for 10 minutes, and I can’t see the problem.

local plots = script.Parent.Plot
local plot

local function giveplot(plr)
	print("PlotGiver fired!")
	for i, plot in pairs(plots:GetChildren()) do
		if plot:WaitForChild("Owner").Value ~= nil then
			print("No owner!")
			plot:WaitForChild("Owner").Value = plr
			plot = plot
			game.ReplicatedStorage.GivenPlot:FireClient(plr, plot)


There’s no error outputted.

1 Like

Have you tried printing the value to make sure it is the desired value?


I just tried that, and now I got a output.

“16:55:48.562 - Attempt to connect failed: Passed value is not a function”
Line 36.
AKA player added.

You’re connecting to the function after you call it, remove the set of parentheses calling the function.
( players.PlayerAdded:Connect(giveplot) )

Okay, let me try that. I’ll see if it works.

Only PlotGiver fired is printed.

What do you mean? If he calls the function before :Connecting to it, it’ll Connect the return value of the function, not the function itself.

The script isn’t in plots.

Are there any errors? The issue might be that plots has no children.

It’s gone now.

Can I see your hierarchy? You might be looping through the wrong thing, since that script works for me.


That looks like mine, it definitely should be printing Looping. Is there anything that could be destroying the Grids? Any other scripts that access them?

No script is destroying it, and it now prints everything.

When you said “not showing the value” do you mean the value never changes or that the client doesn’t ever get the event?

The value never changes.

If there’s no errors, I don’t know why your script doesn’t work. I can run your script and have it work fine, so it’s probably the issue of another script in your game.

I’m back, and I don’t think it is because I have only two scripts in the explorer, and both of them don’t destroy anything.

Edit: didn’t see the picture right :frowning:

I believe the problem here is your checking all the descendants of the plot folder, including those scripts. Since the scripts don’t have an Owner value, it’s infinitely waiting. Try adding: if plot:IsA(“Part”) then, right after your loop starts. Don’t forget to add in another end as well.

The scripts aren’t in the plot folder, look at his hierarchy picture.