I’m currently having an issue with my plot-claiming system.
The script below is supposed to ensure that each player can claim only one plot. However, when a player claims a plot, they are still able to claim another one, which is not what I intended.
I’d appreciate it if you could help me figure out what to add or remove to fix this issue.
local Workspace = game:GetService("Workspace")
local PlotFolder = Workspace.Plots
local PlotList = PlotFolder:GetChildren()
for _, plot in PlotList do
plot.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if plot:GetAttribute("Taken") ~= nil then
return
else
plot:SetAttribute("Taken", true)
plot:SetAttribute("Owner", player.Name)
print(player.Name .. "has claimed this plot")
end
print(player.Name .. " has touched the plot")
end
end)
end
game.Players.PlayerRemoving:Connect(function(player)
for _, plot in PlotList do
if plot:GetAttribute("Owner") == player.Name then
plot:SetAttribute("Taken", nil)
plot:SetAttribute("Owner", nil)
print(player.Name .. "has unclaimed this plot")
else if plot:GetAttribute("Owner") ~= player.Name then
continue
end
end
break
end
end)
Oh, and by the way, I’m using a Part as a placeholder for the plot, regardless of its size, rather than a Model.