local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
Rot += Vector3.new(0, -90, 0)
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
if ObjToSpawn.Name ~= nil then
local Ghost = ObjToSpawn:Clone()
Ghost.Parent = script.Parent
Ghost.Name = "Ghost"
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end
end)
script.Parent.Activated:Connect(function()
script.Parent.place:FireServer(Positiona, Rot)
end)
The.OnClientEvent:Connect(function(plrr, object)
print("stating"..object.Name)
if plrr == game.Players.LocalPlayer.Name then
print(object.Name)
ObjToSpawn = object
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
end
end)
Mouse.Move:Connect(function()
local GridSize = nil
print(typeof(ObjToSpawn))
if ObjToSpawn.Name == "Wire" then
GridSize = 1
print("gridsize1")
else
GridSize = 4
print("gridsize4")
end
local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
Positiona = CFrame.new(X, Y, Z)
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
if ObjToSpawn ~= nil then
local Ghost = ObjToSpawn:Clone()
Ghost.Parent = script.Parent
Ghost.Name = "Ghost"
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end)
when doing objecttospawn.name it says attempt to index nil with name
objecttospawn is an instance, so idk why its doing this
local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
Rot += Vector3.new(0, -90, 0)
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
if ObjToSpawn ~= nil then
local Ghost = ObjToSpawn:Clone()
Ghost.Parent = script.Parent
Ghost.Name = "Ghost"
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end
end)
script.Parent.Activated:Connect(function()
script.Parent.place:FireServer(Positiona, Rot)
end)
The.OnClientEvent:Connect(function(plrr, object)
print("stating"..object.Name)
if plrr == game.Players.LocalPlayer.Name then
print(object.Name)
ObjToSpawn = object
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
end
end)
Mouse.Move:Connect(function()
local GridSize = nil
print(typeof(ObjToSpawn))
if ObjToSpawn.Name == "Wire" then
GridSize = 1
print("gridsize1")
else
GridSize = 4
print("gridsize4")
end
local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
Positiona = CFrame.new(X, Y, Z)
if script.Parent:FindFirstChild("Ghost") then
script.Parent.Ghost:Destroy()
end
if ObjToSpawn ~= nil then
local Ghost = ObjToSpawn:Clone()
Ghost.Parent = script.Parent
Ghost.Name = "Ghost"
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end)
Maybe this will work? I saw that the way you’re making the ghost block move is by destroying and adding it back everytime the mouse moves… so, that might be the problem…
local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")
local Ghost
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
Rot += Vector3.new(0, -90, 0)
if ObjToSpawn ~= nil then
if Ghost == nil then
Ghost = ObjToSpawn:Clone()
Ghost.Name = "Ghost" .. ObjToSpawn.Name
elseif Ghost ~= nil and "Ghost" .. ObjToSpawn.Name ~= Ghost.Name then
Ghost:Destroy()
Ghost = ObjToSpawn:Clone()
Ghost.Name = "Ghost" .. ObjToSpawn.Name
end
if Ghost ~= nil then
Ghost.Parent = script.Parent
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end
end
end)
script.Parent.Activated:Connect(function()
script.Parent.place:FireServer(Positiona, Rot)
end)
The.OnClientEvent:Connect(function(plrr, object)
print("stating"..object.Name)
if plrr == game.Players.LocalPlayer.Name then
print(object.Name)
ObjToSpawn = object
end
end)
Mouse.Move:Connect(function()
local GridSize = nil
print(typeof(ObjToSpawn))
if ObjToSpawn.Name == "Wire" then
GridSize = 1
print("gridsize1")
else
GridSize = 4
print("gridsize4")
end
local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
Positiona = CFrame.new(X, Y, Z)
if ObjToSpawn ~= nil then
if Ghost == nil then
Ghost = ObjToSpawn:Clone()
Ghost.Name = "Ghost" .. ObjToSpawn.Name
elseif Ghost ~= nil and "Ghost" .. ObjToSpawn.Name ~= Ghost.Name then
Ghost:Destroy()
Ghost = ObjToSpawn:Clone()
Ghost.Name = "Ghost" .. ObjToSpawn.Name
end
if Ghost ~= nil then
Ghost.Parent = script.Parent
Ghost:SetPrimaryPartCFrame(Positiona)
Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
for _, V in pairs(ObjToSpawn:GetChildren()) do
if V:IsA("BasePart") then
V.Transparency = 0.8
V.Color = Color3.new(0, 0, 0)
end
end
end
end
end)
well i didnt want it to do that anyways, i am making a new “wiretool”, where when you hover over an object, it snaps the plug to the object… im having problems makign that work. can you help?