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.
-- 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.
-- 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)
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.