here’s the script:
local Plots = game.Workspace.Plots
local TemplateWarehouse = game.Workspace.TemplateWarehouse
game.Players.PlayerAdded:Connect(function(player)
for _, plot in Plots:GetChildren() do
if plot:GetAttribute("Taken") then continue end
plot:SetAttribute('Taken', true)
plot:SetAttribute('Owner', player.UserId)
print('Plot has been given to '..player.Name..'!')
local ItemsFolder = Instance.new('Folder')
ItemsFolder.Name = 'Items'
ItemsFolder.Parent = plot
local ButtonsFolder = Instance.new('Folder')
ButtonsFolder.Name = 'Buttons'
ButtonsFolder.Parent = plot
local TemplateButtons = TemplateWarehouse.Buttons:Clone()
TemplateButtons.Parent = workspace.TemplateWarehouse
print(TemplateButtons)
local TemplateItems = TemplateWarehouse.Items
for _, Button in TemplateButtons:GetChildren() do
local RelativeCFrame = TemplateWarehouse:GetPivot():ToObjectSpace(Button:GetPivot())
Button:PivotTo(plot:GetPivot():ToWorldSpace(RelativeCFrame))
Buttons.Button["InvisablePart"].Touched:Connect(function()
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
if plot:GetAttribute('Owner') ~= player.UserId then return end
local itemToUnlockId = Button:GetAttribute('IdOfItemToUnlock')
if not itemToUnlockId then warn ('You forgot to add an IdOfItemToUnlock attribute') return end
for _, item in TemplateItems:GetChildren() do
if item:GetAttribute('Id') ~= itemToUnlockId then continue end
local itemClone = item:Clone()
local itemCFrame
if itemClone:IsA('Model') then
itemCFrame = itemClone:GetPivot()
elseif itemClone:IsA('BasePart') then
itemCFrame = itemClone.CFrame
end
local relativeItemCFrame = TemplateWarehouse.CFrame:ToObjectSpace(itemCFrame)
if itemClone:IsA('Model') then
itemClone:PivotTo(TemplateWarehouse.CFrame:ToWorldSpace(relativeItemCFrame))
elseif itemClone:IsA('BasePart') then
itemClone.CFrame = TemplateWarehouse.CFrame:ToWorldSpace(relativeItemCFrame)
end
itemClone.Parent = ItemsFolder
end
end)
Button.Parent = ButtonsFolder
end
TemplateButtons.Parent = plot
break
end
end)
game.Players.PlayerRemoving:Connect(function(player)
for _, plot in Plots:GetChildren() do
if plot:GetAttribute("Owner") then continue end
if plot:GetAttribute("Owner") ~= player.UserId then continue end
plot:SetAttribute('Taken', nil)
plot:SetAttribute('Owner', nil)
print('Plot has been removed from '..player.Name..'!')
break
end
end)
i don’t know how to fix the button part and the touch part
