Proximity Prompt Triggered When Switching Tools

Hello.
So I am Working On A Game And.
I Wanna Make A Tools That Breaks The Window
When i Click The Proximity Prompt When Not Holding A Tool
Nothing Happens But.
If I Equip The Tool. The Window Disappears And
The Proximity Prompt Moves To 0, 0, 0. Its Not In The Explorer Either

Code :

local Proximity = script.Parent.ProximityPrompt
local Sound = script.Parent.Sound

Proximity.Triggered:Connect(function(Player)
	if Player.Character:WaitForChild("Hammer") then
		Sound:Play()
		script.Parent.Parent:Destroy()
	end
end)

I Am Still A Beginner And Cant Really Understand Something.

1 Like

Switch out Player.Character:WaitForChild("Hammer") for Player.Character:FindFirstChild("Hammer")

WaitForChild will yield the currently running thread until it finds the object specified.
This means that, once you run that function, instead of ending if you don’t have a hammer equipped, it’ll wait for you to equip the hammer.

FindFirstChild instead returns nil if the object doesn’t exist, instead of yielding until the object is found.
By switching to this, the function will end properly if the player doesn’t have a hammer equipped, and won’t wait for them to equip it.

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