Hi! I was making a storage shelf in a game I’m working on. You hold E, and if you’re holding a tool then it’ll put it on the shelf. However, when it’s activated, not only did it activate both things, it says “tried to index nil with ‘:Clone()’” Help would be appreciated!
item = false
stored = ""
script.Parent.Hold.Triggered:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
if char:FindFirstChildWhichIsA("Tool") and item == false then
script.Parent.Hold.Enabled = false
local tool = char:FindFirstChildWhichIsA("Tool")
local handle = tool.Handle
handle.Name = tool.Name
handle.Parent = workspace
handle.Position = script.Parent.Position
handle.CanCollide = true
handle.Anchored = true
tool:Destroy()
item = true
stored = handle.Name
script.Parent.Hold.ActionText = "Take"
script.Parent.Hold.ObjectText = "Retrieve your ".. handle.Name ..""
script.Parent.Hold.Enabled = true
end
if item == true then
script.Parent.Hold.Enabled = false
local tool = game.ReplicatedStorage:WaitForChild("Tool")
local part = script.Parent:FindFirstChild(stored)
local char = player.Character or player.CharacterAdded:Wait()
local newtool = tool:Clone()
local newpart = part:Clone() -- problem
part.Name = "Handle"
part.Parent = newtool
newtool.Parent = char
newpart.Transparency = 1
newpart.CanCollide = false
newpart.Anchored = true
newtool.Name = newpart.Name
newpart.Parent = newtool
item = false
stored = ""
script.Parent.Hold.ActionText = "Store"
script.Parent.Hold.ObjectText = "Store holding item"
script.Parent.Hold.Enabled = true
end
end)