Plot claiming help

Hi,

So I made a thing where if a player joins the map, they’re assigned to a plot. I tried testing it with multiple player’s through studio’s own testing thing, but it doesn’t seem to be working.

This is my script in serverscriptservice:

local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
	for i,v in pairs(workspace.Plots:GetChildren()) do
		if v:FindFirstChild("plr").Value ~= nil then continue end
		print(v)
		v:FindFirstChild("plr").Value = plr
		v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
		local chr = plr.Character or plr.CharacterAdded:Wait()
		task.wait()
		chr.HumanoidRootPart.CFrame = v:FindFirstChild("Spawn").CFrame
		break
 	end
end)

1 Like

Are you getting a error or is it just not assigning it to them?

1 Like

I’m on mobile currently but I believe you do not need the “continue end” you just need a simple if then statement

1 Like

It’s just not assigning them. No errors for me.

1 Like

Here is my new code. I tried testing with players, but they don’t spawn on their plot, they spawn in the middle of the map.

image

local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
	for i,v in pairs(workspace.Plots:GetChildren()) do
		if v:FindFirstChild("plr").Value ~= nil then continue end
		print(v)
		v:FindFirstChild("plr").Value = plr
		v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
		local chr = plr.Character or plr.CharacterAdded:Wait()
		task.wait()
		chr.HumanoidRootPart.CFrame = v:FindFirstChild("Spawn").CFrame
		break
	end
end)

plrs.PlayerRemoving:Connect(function(plr)
	for i,v in pairs(workspace.Plots:GetChildren()) do
		if v:FindFirstChild("plr").Value == nil then continue end
		local owned_by = v:FindFirstChild("plr").Value
		if owned_by == plr then
			v:FindFirstChild("plr").Value = nil
			v.sign.Text.SurfaceGui.TextLabel.Text = "Unclaimed"
			break
		end
	end
end)

this is pretty simple, do you still need help? did you try debugging?

Yes, I still need help. Do you have any solutions? :slight_smile:

Try this code,
instead of setting the character’s HumanoidRootPart CFrame to “Spawn” part CFrame you need to set the character’s HumanoidRootPart CFrame to a new CFrame from “Spawn” part’s position.

plrs.PlayerAdded:Connect(function(plr)
     plr.CharacterAdded:Connect(function()
	for i,v in pairs(workspace.Plots:GetChildren()) do
		if v:FindFirstChild("plr").Value ~= nil then continue end
		print(v)
		v:FindFirstChild("plr").Value = plr
		v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
		local chr = plr.Character or plr.CharacterAdded:Wait()
		task.wait()
		chr.HumanoidRootPart.CFrame = CFrame.new(v:FindFirstChild("Spawn").Position)
		break
	end
end)
end)

plrs.PlayerRemoving:Connect(function(plr)
	for i,v in pairs(workspace.Plots:GetChildren()) do
		if v:FindFirstChild("plr").Value == nil then continue end
		local owned_by = v:FindFirstChild("plr").Value
		if owned_by == plr then
			v:FindFirstChild("plr").Value = nil
			v.sign.Text.SurfaceGui.TextLabel.Text = "Unclaimed"
			break
		end
	end
end)

Maybe when you use ~= nil, put ~= “”.