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))
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
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.
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
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
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))
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
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)