Assigning Plot owner

Hello everyone,

When I try to assign a player to the plot, the player gets assigned to all of them:
Ask if I need to clarify.

Players.PlayerAdded:Connect(function(player)
	for _,plot in pairs(game.Workspace:GetChildren()) do
		if plot.Name == "Plot" then
			for _,plotOwner in pairs(plot:GetChildren()) do
				if plotOwner.Value == nil then
					plotOwner.Value = player
					print(plotOwner.Value)
				end			
			end
		end
	end
end)

Thanks for the Help!

2 Likes

You could add a break inside the loop right after plotOwner.Value = player so the player would only be assigned to one

3 Likes

Doesn’t seem to work, still the same result

1 Like

Which line is having the issue, did you try debugging?

1 Like

It is not the issue, it just seems to assign one player to the every plot

1 Like

Set it to player.Name, not the player instance

1 Like

I have a instance value, not a string value

1 Like

player is an instance, you can’t set the player to a value, you need their name or id.

1 Like

You seem to be looping through every individual child in the plot? You can simply just do:

Players.PlayerAdded:Connect(function(player)
	for _,plot in pairs(game.Workspace:GetChildren()) do
		if plot.Name == "Plot" then
			if plot:FindFirstChild("plotOwner").Value == nil then
				--assign value		
			end
		end
	end
    return false
end)

Can’t guarantee this will work, but your code is using much more lines than it needs

2 Likes

When I print it out, print(plotOwner.Value), it works; like it shows the player name

1 Like

@ijmod, it works, but why return false at the end?

You can use that return value in the future, it’s not needed but it’s a way to use it for returning a value.

You could most likely take that part out and it’ll still function as intended, but let’s say this code was nested inside of a function, you can return false instead of nothing so you know that the for loop didn’t find any matches

Thanks for the responses, that helped me understand!

1 Like

I don’t understand? I always used things like that. I always used an Object Value and put the player as the value, it always has worked for me…

It’s easier to call the player’s name or find their ID.