Code Issues - Cloning Model onto Activated Tool

Hello! I’m trying to make the plate clone and be placed under my activated tool (only the one that is activated). What am I doing wrong?

Below you can see the console output of my code:

server-script:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local tool = humanoid:FindFirstChild("Activated") -- Buscar la herramienta activada
				if tool then
					print("Tool activated for player:", player.Name)
					-- Clonar el modelo del plato debajo de la herramienta
					local plateClone = plateModel:Clone()
					plateClone.Parent = tool
					plateClone:SetPrimaryPartCFrame(tool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Ajustar la posición debajo de la herramienta
					print("Plate cloned and positioned under activated tool for player:", player.Name)
				else
					print("No activated tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)
1 Like

i mean nothing but is the Activated located inside the humanoid??

2 Likes

Hmm, you’re right. Look, I tried it this way and it still doesn’t work. It prints the following:

server-script:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				-- Connect the Activated event outside the for loop
				local activatedTool = nil
				for _, tool in pairs(player.Backpack:GetChildren()) do
					if tool:IsA("Tool") then
						if tool.Activated then
							tool.Activated:Connect(function()
								activatedTool = tool
							end)
						end
					end
				end

				-- Wait a short time for the Activated event to be triggered
				wait(0.1)

				-- Check for an activated and equipped tool
				if activatedTool and activatedTool:IsEquipped() then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)
1 Like

i dont think “if tool.Activated” is needed it prevent the event from running try to delete it.I might be wrong

1 Like

I tried it, and it still doesn’t work. What could be wrong? :confused:

1 Like

If you can put some prints inside that part too to check which one prevent it from working

1 Like

I tried this and added debug prints, and this is the result, but it still doesn’t perform the cloning or check for the activated state in the tool.

script:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local activatedTool = nil

				-- Connect the Activated event outside the loop
				local backpack = player.Backpack:GetChildren()
				for _, tool in ipairs(backpack) do
					if tool:IsA("Tool") then
						print("Connecting Activated event for tool:", tool.Name)
						tool.Activated:Connect(function()
							activatedTool = tool
						end)
					end
				end

				-- Wait for the Activated event to be triggered
				wait(0.1)

				-- Check for an activated and equipped tool
				if activatedTool and activatedTool:IsEquipped() then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)
1 Like

You’re searching for the tool inside of the Humanoid instead of the Character

When a player equips a tool it’s parented to the Character not the Humanoid

check this updated script please :pray: @JohhnyLegoKing

Uuuh no he’s right. What he meant is finding the tool in Player Character not in player backpack
You can change to
Local backpack = character:GetDescendants()

1 Like

Oh, I see… Look, I tried it, but I’m getting the same result. :frowning:


Replace the code in your server script with this:

local plateModel = script.Parent
local proxPrompt = plateModel.base.ProximityPrompt

local function onTriggered(player)
	if player.Character then
		local tool = player.Character:FindFirstChild("Activated")

		if tool then
			local plateClone = plateModel:Clone()
			plateClone:PivotTo(tool.Handle.CFrame * CFrame.new(0, -1, 0))
			plateClone.Parent = tool
		end
	end
end

proxPrompt.Triggered:Connect(onTriggered)

Alr remove the tool.Activated event it doesn’t help much change to if tool.Activated instead
I dont think activatedTool is set

Oh! I managed to solve it! :smiley:
Now I just need to remove the proximity prompt from my cloned part, anchor it to my tool, and take care of those details. Thanks for the help! Who do I give the resolve to? Everyone helped me a lot.

server-script:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local activatedTool = nil

				-- Connect the Activated event outside the loop
				local backpack = character:GetChildren()
				for _, tool in ipairs(backpack) do
					if tool:IsA("Tool") then
						print("Connecting Activated event for tool:", tool.Name)
						if tool.Activated then
							activatedTool = tool
							break
						end
					end
				end

				-- Wait for the Activated event to be triggered
				wait(0.1)

				-- Check if the activated tool is equipped
				if activatedTool and activatedTool.Parent == character then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)

You can make this post the solution.
Post are asked for solution after all and you made it

just do plate.clone.proxitypormpt (idk how is the proxim named).enabled = false after PlateClone is cloned

This should work to make the model move with the Tool

It’s guaranteed to remove the prompt from the clone at least:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local activatedTool = nil

				-- Connect the Activated event outside the loop
				local backpack = character:GetChildren()
				for _, tool in ipairs(backpack) do
					if tool:IsA("Tool") then
						print("Connecting Activated event for tool:", tool.Name)
						if tool.Activated then
							activatedTool = tool
							break
						end
					end
				end

				-- Wait for the Activated event to be triggered
				wait(0.1)

				-- Check if the activated tool is equipped
				if activatedTool and activatedTool.Parent == character then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.base.ProximityPrompt:Destroy()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)

					local weld = Instance.new("WeldConstraint")
					weld.Part0 = activatedTool.Handle
					weld.Part1 = plateClone.base
					weld.Parent = activatedTool

					plateClone.base.Anchored = false
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)

@PipeSader This method might work better if the Model contains multiple parts:

local proxPrompt = script.Parent.base.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local activatedTool = nil

				-- Connect the Activated event outside the loop
				local backpack = character:GetChildren()
				for _, tool in ipairs(backpack) do
					if tool:IsA("Tool") then
						print("Connecting Activated event for tool:", tool.Name)
						if tool.Activated then
							activatedTool = tool
							break
						end
					end
				end

				-- Wait for the Activated event to be triggered
				wait(0.1)

				-- Check if the activated tool is equipped
				if activatedTool and activatedTool.Parent == character then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.base.ProximityPrompt:Destroy()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)

					for _, instance in plateClone:GetDescendants() do
						if instance:IsA("BasePart") then
							local weld = Instance.new("WeldConstraint")
							weld.Part0 = activatedTool.Handle
							weld.Part1 = instance
							weld.Parent = activatedTool

							instance.Anchored = false
						end
					end
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)

Oh thanks it works but i’m having the following issue:

server script:

local proxPrompt = script.Parent.Handle.ProximityPrompt
local plateModel = script.Parent

proxPrompt.Triggered:Connect(function(player)
	print("Proximity prompt triggered")
	if player then
		print("Player found:", player.Name)
		local character = player.Character
		if character then
			print("Character found for player:", player.Name)
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				print("Humanoid found for player:", player.Name)
				local activatedTool = nil

				-- Connect the Activated event outside the loop
				local backpack = character:GetChildren()
				for _, tool in ipairs(backpack) do
					if tool:IsA("Tool") then
						print("Connecting Activated event for tool:", tool.Name)
						if tool.Activated then
							activatedTool = tool
							break
						end
					end
				end

				-- Wait for the Activated event to be triggered
				wait(0.1)

				-- Check if the activated tool is equipped
				if activatedTool and activatedTool.Parent == character then
					print("Activated and equipped tool found for player:", player.Name)
					-- Clone the plate model under the activated and equipped tool
					local plateClone = plateModel:Clone()
					plateClone.Handle.ProximityPrompt:Destroy()
					plateClone.Parent = activatedTool
					plateClone:SetPrimaryPartCFrame(activatedTool.Handle.CFrame * CFrame.new(0, -1, 0)) -- Adjust the position under the tool
					print("Plate cloned and positioned under activated and equipped tool for player:", player.Name)

					for _, instance in plateClone:GetDescendants() do
						if instance:IsA("BasePart") then
							local weld = Instance.new("WeldConstraint")
							weld.Part0 = activatedTool.Handle
							weld.Part1 = instance
							weld.Parent = activatedTool

							instance.Anchored = false
						end
					end
				else
					print("No activated and equipped tool found for player:", player.Name)
				end
			else
				print("No humanoid found for player:", player.Name)
			end
		else
			print("No character found for player:", player.Name)
		end
	else
		print("No player found")
	end
end)

Here you wrote:

Instead of:

From what I understand the prompt is located in the Model’s base, not Handle

Oh yes sorry lol i just changed the name of the Base to Handle

image

here is the error:

1 Like