game.ReplicatedStorage.Remotes.SetPlayerStatus.OnServerEvent:Connect(function(plr, status, ...)
local args = {...}
PlayerData:AddOrSetNumber(plr, status, "PlayerStatus")
if args[1] ~= nil then
plr.playerdata.ObjectBeingPlaced.Value = args[1]
end
end)
local PlayerData = {}
local function GetOrCreateDataHolder(plr)
if not plr:FindFirstChild("playerdata") then
local pdata = Instance.new("Folder")
pdata.Name = "playerdata"
pdata.Parent = plr
end
return plr:FindFirstChild("playerdata")
end
local function Add(datatype, plr, value, name)
if not GetOrCreateDataHolder(plr):FindFirstChild(name) then
local i = Instance.new(datatype)
i.Value = value
i.Name = name
i.Parent = GetOrCreateDataHolder(plr)
else
local d = GetOrCreateDataHolder(plr):FindFirstChild(name)
d.Value = value
end
end
function PlayerData:AddOrSetString(plr, value, name)
Add("StringValue", plr, value, name)
end
function PlayerData:AddOrSetNumber(plr, value, name)
Add("NumberValue", plr, value, name)
end
function PlayerData:AddOrSetBool(plr, value, name)
Add("BoolValue", plr, value, name)
end
function PlayerData:GetData(plr, name)
if not GetOrCreateDataHolder(plr):FindFirstChild(name) then
return false
end
return GetOrCreateDataHolder(plr):FindFirstChild(name)
end
function PlayerData:RemoveData(plr, name)
if not GetOrCreateDataHolder(plr):FindFirstChild(name) then
return false
end
GetOrCreateDataHolder(plr):FindFirstChild(name):Destroy()
return true
end
return PlayerData
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local remote = ReplicatedStorage.Remotes:WaitForChild("RequestPlacement")
local button = script.Parent
local PlacementModule = require(ReplicatedStorage.Modules:WaitForChild("PlacementModuleV3"))
local isDeleting = false
local deleteHL = Instance.new("SelectionBox")
deleteHL.Color3 = Color3.fromRGB(250, 46, 46)
deleteHL.Transparency = 0.5
deleteHL.LineThickness = 0.1
coroutine.wrap(function()
while true do
if isDeleting then
if mouse.Target ~= nil then
if mouse.Target.Parent.Parent.Parent ~= nil then
if mouse.Target.Name == "Hitbox" and mouse.Target.Parent.Parent.Parent == workspace.Plots:FindFirstChild(player.playerdata.Plot.Value) then
deleteHL.Adornee = mouse.Target
deleteHL.Parent = mouse.Target
deleteHL.Visible = true
else
deleteHL.Adornee = nil
deleteHL.Parent = nil
deleteHL.Visible = false
end
end
end
end
task.wait()
end
end)()
local placementInfo = PlacementModule.new(
2,
ReplicatedStorage.Models,
Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.U, Enum.KeyCode.L,
Enum.KeyCode.ButtonR1, Enum.KeyCode.ButtonX, Enum.KeyCode.DPadUp, Enum.KeyCode.DPadDown
)
local function requestDeletion()
if isDeleting then
local obj = mouse.Target
if obj then
if obj.Parent.Parent.Parent == workspace.Plots:FindFirstChild(player.playerdata.Plot.Value) then
game.ReplicatedStorage.Remotes.DeleteItem:FireServer(obj)
end
end
end
end
button.MouseButton1Click:Connect(function()
if player.playerdata.ObjectBeingPlaced.Value == "None" then
if player.playerdata.PlayerStatus.Value == 1 then
if player.playerdata:FindFirstChild(script.Parent.TextLabel.Text).Value > 0 then
local plot = workspace.Plots:FindFirstChild(player.playerdata.Plot.Value)
placementInfo:activate(script.Parent.TextLabel.Text, plot.ItemHolder, plot, false, false, false)
game.ReplicatedStorage.Remotes.SetPlayerStatus:FireServer(2, script.Parent.TextLabel.Text)
end
end
end
end)
mouse.Button1Down:Connect(function()
if player.playerdata.ObjectBeingPlaced.Value == script.Parent.TextLabel.Text then
if player.playerdata.PlayerStatus ~= nil then
if player.playerdata.PlayerStatus.Value == 2 and not isDeleting then
if player.playerdata:FindFirstChild(script.Parent.TextLabel.Text) then
if player.playerdata:FindFirstChild(script.Parent.TextLabel.Text).Value > 0 then
placementInfo:requestPlacement(remote)
game.ReplicatedStorage.Remotes.PlaceObjectServer:FireServer()
end
end
end
if player.playerdata.PlayerStatus.Value == 3 and isDeleting then
requestDeletion()
end
end
end
end)
game.ReplicatedStorage.Bindables.SyncBulldoze.Event:Connect(function(bl)
if game.Players.LocalPlayer.playerdata.ObjectBeingPlaced.Value == script.Parent.TextLabel.Text then
isDeleting = bl
end
end)
status
Lets me know if the player is not placing or destroying anything (if the value == 1
), placing an object (if the value == 2
), or destroying an object (if the value == 3
)