What do you want to achieve? Keep it simple and clear!
I’m trying to make a tool where when you use it, it will place a part in front of the player
What is the issue? Include screenshots / videos if possible!
When the part is cloned and parented into the workspace, the green outline of another part won’t get destroy with the error saying “attempt to index nil with ‘Destroy’”
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
No solution so far
script.Parent.OnServerEvent:Connect(function()
local HumRP = script.Parent.Parent.Parent.Parent:FindFirstChild("HumanoidRootPart") or script.Parent.Parent.Parent.Parent.Parent.Character:FindFirstChild("HumanoidRootPart")
local Hum = script.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") or script.Parent.Parent.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")
local Pos = HumRP.CFrame
local Clone = game.ReplicatedStorage.Parts.Part8X8:Clone()
wait(1)
Clone.Parent = game.Workspace.Build
Clone.CFrame = Pos * CFrame.new(0,0,-8)
local Weld = HumRP:FindFirstChild("Cloned8x8Weld")
local Cloned = HumRP:FindFirstChild("Cloned8x8")
Weld:Destroy()
Cloned:Destroy()
script.Parent.Parent.Parent:Destroy()
end)
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent") --change to name of remoteevent instance
local parts = rs:WaitForChild("Parts")
local part8x8 = parts:WaitForChild("Part8x8")
local build = workspace:WaitForChild("Build")
re.OnServerEvent:Connect(function(player)
local character = player.Character
local hrp = character:WaitForChild("HumanoidRootPart")
local hum = character:WaitForChild("Humanoid")
local partClone = part8x8:Clone()
task.wait(1)
partClone.Parent = build
partClone.CFrame = hrp.CFrame * CFrame.new(0, 0, -8)
local Weld = hrp:FindFirstChild("Cloned8x8Weld")
local Cloned = hrp:FindFirstChild("Cloned8x8")
if Weld then
Weld:Destroy()
end
if Cloned then
Cloned:Destroy()
end
character:BreakJoints()
end)
Move the RemoteEvent instance to the ReplicatedStorage folder so that it replicates to the client (so that the client can use it when calling “FireServer()” from some local script. Remember that whenever a local script calls “FireServer()” through a RemoteEvent instance from a local script the player object pertaining to the particular client which fired the server is automatically passed as an argument to any callback function connected to any corresponding OnServerEvent event listener created through the same RemoteEvent instance in some server script, as such all we need to do is declare a parameter with a suitable name to handle this received value (player object) on the server’s side.