Create plot system does not work right

im trying to make plot system but neither the positioning works and it tries to clone the plot 3 times
robloxapp-20230906-1958418.wmv (857.0 KB)

the Code:

local command = “!createplot”

local function plotcreate(player)
if not game.Workspace.PlotFolder:FindFirstChild(player.Name… “'s Plot”) then–checking if player has plot
local plot = game.ReplicatedStorage.Plot:Clone()
plot.Parent = game.Workspace.PlotFolder
plot:MoveTo(player.Character:WaitForChild(“HumanoidRootPart”).CFrame.Position * Vector3.new(0,-3,0))

  plot.Name = player.Name.. "'s Plot"
  player.PlayerGui.notifygui.TEXT.Text = "plot created"--popuptext
  wait(1)
  player.PlayerGui.notifygui.TEXT.Text = ""

else–players already has a plot made

  player.PlayerGui.notifygui.TEXT.Text = "You Already Have A Plot"--popuptext
  wait(2)
  player.PlayerGui.notifygui.TEXT.Text = ""

end
end

local plrbase = game:GetService(“Players”)
plrbase.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if msg == command then

  	for _, object in pairs(workspace:GetChildren()) do --if you want to check the workspace
  		if object: IsA("BasePart") then
  			if (player.Character:WaitForChild("HumanoidRootPart").Position - object.Position).Magnitude < 105 then--gettin parts close to 105 studs
  				if object.Parent.Parent.Name ~= "PlotFolder" then--checking if there is a plot nearby
  					plotcreate(player)
  				end
  			end
  		end
  	end
  end

end)
end)

1 Like
External Media

i hope roblox didnt screw this embed

1 Like

I can give you one thing you might need to fix.
when checking the workspace, you should probably check GetDescendants() and not GetChildren() because if the object is a child of the workspace then object.Parent.Parent.Name is always going to be game’s Name, which i doubt is what you want.

1 Like

i changed the getchildren also the object parent is im searching for is parented to a folder

1 Like

if msg == command then
for index, torsos in pairs(workspace:GetDescendants()) do
if (torsos.Position - player:WaitForChild(“HumanoidRootPart”).Position).Magnitude < 105 then
if torsos.Parent.Parent.Name ~= “PlotFolder” then
plotcreate(player)
end
end
end
end

1 Like

This part is never going to happen, you need to do player.Character:WaitForChild(“HumanoidRootPart”)

2 Likes

also you need to make sure you have some sort of assurance that the ‘torsos’ is a part, so you dont get an error when doing torsos.Position

2 Likes

also I just realized, but in this case you probably want to do Workspace.PlotFolder:GetDescendants() because you dont need anything else that is not a descendant of workspace

2 Likes

so it should be like this?

local command = “!createplot”

local function plotcreate(player)
if not game.Workspace.PlotFolder:FindFirstChild(player.Name… “'s Plot”) then–checking if player has plot
local plot = game.ReplicatedStorage.Plot:Clone()
plot.Parent = game.Workspace.PlotFolder
plot:MoveTo(player.Character:WaitForChild(“HumanoidRootPart”).CFrame.Position * Vector3.new(0,-3,0))

  plot.Name = player.Name.. "'s Plot"
  player.PlayerGui.notifygui.TEXT.Text = "plot created"--popuptext
  wait(1)
  player.PlayerGui.notifygui.TEXT.Text = ""

else–players already has a plot made

  player.PlayerGui.notifygui.TEXT.Text = "You Already Have A Plot"--popuptext
  wait(2)
  player.PlayerGui.notifygui.TEXT.Text = ""

end
end

local plrbase = game:GetService(“Players”)
plrbase.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if msg == command then
for index, torsos in pairs(workspace.PlotFolder:GetDescendants()) do
if torsos:IsA(“Part”) and (torsos.Position - player.Character:WaitForChild(“HumanoidRootPart”).Position).Magnitude < 105 then

  			 plotcreate(player)
  		
  		end
  	end
  end

end)
end)

1 Like

That looks right, why dont you run it now and see it any errors pop up

1 Like

runned it, did not work but also no errors on the console???

1 Like

try debugging it to see what lines run, and what if statements are passed

1 Like
local command = "!createplot"
local PlotFolder = workspace:WaitForChild('PlotFolder')
local Plot = game.ReplicatedStorage:WaitForChild('Plot')
local plrbase = game:GetService("Players")


local function plotcreate(player)
	if not workspace.PlotFolder:FindFirstChild(player.Name .. "'s Plot") then -- checking if player has plot
		local plot = Plot:Clone()
		plot.Parent = PlotFolder
		plot.Name = player.Name .. "'s Plot"
		if not player.Character:FindFirstChild('HumanoidRootPart') then 
			warn('Failed to grab HumanoidRootPart!')
			return
		end
		plot:MoveTo(player.Character:FindFirstChild("HumanoidRootPart").CFrame.Position + Vector3.new(0,-3,0))
		player.PlayerGui.notifygui.TEXT.Text = "plot created"--popuptext
		task.wait(1)
		player.PlayerGui.notifygui.TEXT.Text = ""
	else -- players already has a plot made
		player.PlayerGui.notifygui.TEXT.Text = "You Already Have A Plot"--popuptext
		task.wait(2)
		player.PlayerGui.notifygui.TEXT.Text = ""
	end
end

plrbase.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == command then
			for _, object in pairs(workspace:GetDescendants()) do --if you want to check the workspace
				if object:IsA("BasePart") then
					if (player.Character:WaitForChild("HumanoidRootPart").Position - object.Position).Magnitude < 105 then--gettin parts close to 105 studs
						if object.Parent.Parent.Name ~= "PlotFolder" then--checking if there is a plot nearby
							plotcreate(player)
						end
					end
				end
			end
		end
	end)
end)


1 Like

it now works as intended just a tiny problem with cloning is you can clone it on other peoples plots which is probably easy to fix [fixed]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.