Im working on a custom placer system that places models and parts.
But the problem is, the ghost that helps people identify where they are placing duplicates itself, and still stays after unequipping.
Can someone give advice? Thanks.
Script
local mouse = game.Players.LocalPlayer:GetMouse()
local existingpart = nil
local soundservice = game:GetService("SoundService")
local debounce = false
local toggled = false
--local animateEvent = script:WaitForChild("select"):WaitForChild("Animate"):WaitForChild("Animation")
script.Parent.Equipped:Connect(function()
local gui = script.Parent.LPIWrench
gui.Parent = game.Players.LocalPlayer.PlayerGui
if toggled == false then
toggled = true
for i,set in ipairs(game.ReplicatedStorage.WrenchModels:GetChildren()) do
if set:IsA("Folder") then
local v = game.ReplicatedStorage.SetTemplate:Clone()
v.Text = set.Name
v.Parent = gui.ExplorerFrame.SetsFrame
end
end
end
end)
game.Players.LocalPlayer.PlayerScripts.Get.Event:Connect(function(askedpart)
task.spawn(function()
part:Destroy()
existingpart:Destroy()
end)
soundservice:PlayLocalSound(script.Parent.select)
existingpart = askedpart
part = existingpart:Clone()
part.Parent = workspace
script.select.Adornee = part
if part:IsA("BasePart") then
part.CanCollide = false
part.CanQuery = false
part.Transparency = 0.5
part.Anchored = true
elseif part:IsA("Model") then
for i, item in ipairs(part:GetDescendants()) do
if item:IsA("BasePart") then
item.CanCollide = false
item.CanQuery = false
item.Transparency = 0.5
item.Anchored = true
end
end
end
i = mouse.Move:Connect(function()
if part:IsA("BasePart") then
task.wait()
part.Position = mouse.Hit.Position
local X = math.round(part.Position.X)
local Y = math.round(part.Position.Y) + 0.75
local Z = math.round(part.Position.Z)
if part.Size.Y % 2 ~= 0 --[[odd]] then
X = math.round(part.Position.X) + 0.5
Z = math.round(part.Position.Z) + 0.5
end
if part.Position ~= Vector3.new(X,Y,Z) then
part.Position = Vector3.new(X,Y+(part.Size.Y/2)- 1 --[[prevent stud rounding from messing things up]] ,Z)
end
elseif part:IsA("Model") then
task.wait()
local X = math.round(mouse.Hit.Position.X)
local Y = math.round(mouse.Hit.Position.Y) + 0.75
local Z = math.round(mouse.Hit.Position.Z)
if part:GetExtentsSize().Y % 2 ~= 0 --[[odd]] then
X = math.round(mouse.Hit.Position.X) + 0.5
Z = math.round(mouse.Hit.Position.Z) + 0.5
end
if part.PrimaryPart.Position ~= Vector3.new(X,Y,Z) then
part:MoveTo(Vector3.new(X,Y+(part:GetExtentsSize().Y/2) - 1,Z))
end
end
end)
j = mouse.Button1Up:Connect(function()
local servercframe
if part:IsA("BasePart") then
servercframe = part.CFrame
elseif part:IsA("Model") then
servercframe = part:GetPivot()
end
script.Parent.Place:FireServer(askedpart.Name,servercframe)
script.select.Color3 = Color3.new(1, 0.752941, 0.12549)
task.wait(0.08)
script.select.Color3 = Color3.new(0, 110 / 255, 1)
end)
k = mouse.KeyDown:Connect(function(key)
if key:lower() == "t" then
if part:IsA("BasePart") then
part.Orientation = Vector3.new(part.Orientation.X, part.Orientation.Y, part.Orientation.Z - 90)
elseif part:IsA("Model") then
local rotation = CFrame.Angles(0,0, math.rad(-90))
local modelCFrame = part:GetPivot()
part:PivotTo(modelCFrame * rotation)
end
end
if key:lower() == "r" then
if part:IsA("BasePart") then
part.Orientation = Vector3.new(part.Orientation.X, part.Orientation.Y - 90, part.Orientation.Z)
elseif part:IsA("Model") then
local rotation = CFrame.Angles(0,math.rad(-90),0)
local modelCFrame = part:GetPivot()
part:PivotTo(modelCFrame * rotation)
end
end
end)
game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
part:Destroy()
i:Disconnect()
j:Disconnect()
k:Disconnect()
end)
while task.wait() do
if game.Players.LocalPlayer.Character.Humanoid.Health < 1 then
part:Destroy()
i:Disconnect()
j:Disconnect()
k:Disconnect()
end
end
end)
game.Players.LocalPlayer.PlayerScripts.Get.Event:Connect(function()
part:Destroy()
i:Disconnect()
j:Disconnect()
k:Disconnect()
end)
script.Parent.Unequipped:Connect(function()
game.Players.LocalPlayer.PlayerGui:FindFirstChild("LPIWrench").Parent = script.Parent
task.spawn(function()
i:Disconnect()
j:Disconnect()
k:Disconnect()
part:Destroy()
end)
script.select.Adornee = nil
end)