Trying to assign position of a part to a clone in a later part in the script

im trying to assign the position of a part to a clone that appears later in the script
when i put the if pin == false infront of the if pin part then it doesnt work
also the script repeats destroying the vectorforce and i cant figure out how to only do it once

	tool.Activated:Connect(function()
		
	if pin then
		
		
			pin = false
			
		tool.modle["Thin Torus 2"]:BreakJoints()
		for count = 0,timah,.1 do
			wait(.1)
				timah -=.1
				
			end
			local kablooey = Instance.new("Part")
			kablooey.Shape = Enum.PartType.Ball
			kablooey.CanCollide = false
			kablooey.Anchored = true
			kablooey.Size = Vector3.new(boomsize,boomsize,boomsize)
			kablooey.Color = Color3.new(1,.3,0)
		kablooey.Transparency = .6
		if thrown == false then
			kablooey.Position = script.Parent.Handle.Position
		elseif thrown == true then
			kablooey.Position = clone.Handle.Position
		end
		
			
			kablooey.Parent = workspace
			game.Debris:AddItem(kablooey,.4)
			kablooey.Touched:Connect(function(targ)

				local human = getHuman(targ)
				if human then
					human.Health -= (((human.Parent.PrimaryPart.Position - kablooey.Position).Magnitude)) * damage
				end
			end)

	end
	
	if pin == false then
		thrown = true
		local clone = game.ReplicatedStorage.he:Clone()
	local CF = tool.modle.tart:GetPivot()
	clone:PivotTo(CF * CFrame.Angles(math.pi/2, 0, 0))
	clone.Parent = workspace
	clone.Handle.Touched:Connect(function()
		wait(.1)
			clone.Ball.VectorForce:Destroy()
end)
	end
	end)
	

It’s because both if statements are checked, so when you set pin = false in the first statement, that also activates the second statement.

Fixed code:

tool.Activated:Connect(function()
	if pin then
		pin = false

		tool.modle["Thin Torus 2"]:BreakJoints()
		
		for count = 0, timah, .1 do
			task.wait(.1)
			timah -=.1
		end
		
		local kablooey = Instance.new("Part")
		kablooey.Shape = Enum.PartType.Ball
		kablooey.CanCollide = false
		kablooey.Anchored = true
		kablooey.Size = Vector3.one * boomsize
		kablooey.Color = Color3.new(1,.3,0)
		kablooey.Transparency = 0.6
		
		if thrown then
			kablooey.Position = clone.Handle.Position
		else
			kablooey.Position = script.Parent.Handle.Position
		end

		kablooey.Parent = workspace	
		kablooey.Touched:Connect(function(targ)
			local human = getHuman(targ)
			
			if human then
				human.Health -= (((human.Parent.PrimaryPart.Position - kablooey.Position).Magnitude)) * damage
			end
		end)
		
		task.wait(0.4)
		kablooey:Destroy()
	else
		thrown = true
		
		local clone = game.ReplicatedStorage.he:Clone()
		local CF = tool.modle.tart:GetPivot()
		clone:PivotTo(CF * CFrame.Angles(math.pi/2, 0, 0))
		clone.Parent = workspace
		clone.Handle.Touched:Connect(function()
			task.wait(.1)
			clone.Ball.VectorForce:Destroy()
		end)
	end
end)
1 Like

it still gives me an error “attempt to index nil with Handle”

That means that either you don’t have an object called Handle on the cloned object, or that you destroyed your clone object somehow, try to check for that.

1 Like

i changed the clone variable since i only need to create 1 clone

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.