Script Broken If I Equipped The Tool While Using ProximityPrompt

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

If this player have a tool, the script can activate.

  1. What is the issue? Include screenshots / videos if possible!

When the player equipped the tool while using the proximityPrompt, its becomes broken.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Detect if the Player equipped the tool or not, it didn’t work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- The Script --
local ProximityPrompt = script.Parent


ProximityPrompt.Triggered:Connect(function(Player)
	
	local Tool = Player.Backpack:FindFirstChild("Lantern")  or Player.Character:FindFirstChild("Lantern")
	ProximityPrompt.Enabled = false
	
	if Tool then
		
		Player.Backpack:FindFirstChild("Lantern"):Destroy()
		wait(0.5)
		game.ServerStorage["Energy Lantern"]:Clone().Parent = Player.Backpack
		
	else
		
		ProximityPrompt.Parent.Error:Play()
	end
	
	wait(2)
	ProximityPrompt.Enabled = true
	
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

well obviously, when a player equips a tool it becomes parented to Character and not Backpack

2 Likes
-- The Script --
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("Lantern") then
       Player.Backpack:FindFirstChild("Lantern"):Destroy()
    elseif Player.Character:FindFirstChild("Lantern") then
       Player.Character:FindFirstChild("Lantern"):Destroy()
    end
    local clone = game.ServerStorage["Energy Lantern"]:Clone()
    clone.Parent = Player.Backpack	
	ProximityPrompt.Enabled = false
	task.wait(2)
	ProximityPrompt.Enabled = true	
end)

Try this and tell me if it works.

A few notes:
-Use task.wait() instead of wait() - it affects performance and it’s more accurate and efficient.
-Notice that when a player owns a tool [depending on how you set it], it mostly would be located in his Backpack. Now, when the player equips that tool, it goes into their character.

1 Like

Not What I want but This helps alot, Thanks btw

This is what i want it to be

-- The Script --
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(Player)
	ProximityPrompt.Enabled = false
	
	if Player.Backpack:FindFirstChild("Lantern") or Player.Character:FindFirstChild("Lantern") then
		local clone = game.ServerStorage["Energy Lantern"]:Clone()
		clone.Parent = Player.Backpack	
		
	end
	
	
	
	if Player.Backpack:FindFirstChild("Lantern") then
		Player.Backpack:FindFirstChild("Lantern"):Destroy()

	elseif Player.Character:FindFirstChild("Lantern") then
		Player.Character:FindFirstChild("Lantern"):Destroy()
	end
	
	
	
	task.wait(2)
	ProximityPrompt.Enabled = true
	
end)
1 Like

Well first off all, they still deserve the solution because, well, it solved your issue. You just “re-organized” it into a way that you like, but many people dislike because it adds extra if statements.

1 Like

1.They didn’t made it so that you have this item to only activate it , they make it so that it only destory the item

  1. If I can mark the solution more than 1 post, I would do.