Event firing whenever tool is deleted

I’m trying to make a prompt appear on the client whenever they equip a tool and disappear whenever it is unequipped. It works perfectly fine, but the problem is when I use the prompt and it deletes the tool the prompt disables for a split second and then re-enables itself. I want the prompt to stay disabled once the tool is destroyed.

Video of prompt working and not working when used

Local Script (inside of tool)

local player = script.Parent.Parent.Parent
local Tool = script.Parent

Tool.Equipped:Connect(function()
	for i,object in pairs(game.Workspace:GetDescendants()) do
		if object.Name == "SmashPrompt" and object:IsA("ProximityPrompt") then
			if object.Parent.Disabled.Value == false then
				object.Enabled = true
			end
		end
	end
end)

Tool.Unequipped:Connect(function()
	for i,object in pairs(game.Workspace:GetDescendants()) do
		if object.Name == "SmashPrompt" and object:IsA("ProximityPrompt") then
			object.Enabled = false
		end
	end
end)

Server Script

local Object = script.Parent
local ProximityPrompt = script.Parent.SmashPrompt
local disabled = script.Parent.Disabled
local debounce = false

ProximityPrompt.Triggered:Connect(function(player)
	local crowbar = player.Character:FindFirstChild("Crowbar")
	if crowbar and debounce == false then
		--and player.Team == "Crew" for when i make teams and its anti-exploitable	
		--debounce = true
		--play animation
		crowbar:Destroy()
		print("box smashed")
		disabled.Value = true
		ProximityPrompt.Enabled = false
	end
end)
3 Likes

EDIT: I solved your problem. What I did is create a function to fire when that ProximityPrompt is Triggered. With that remote event, it does a check of the Disabled value to see if it is true to disable the ProximityPrompt. Also, I modified the code a bit.

Here is the code:

Server Side (inside Part)

local Object = script.Parent

local ProximityPrompt = game.Workspace.Part.SmashPrompt

local disabled = script.Parent.Disabled

local debounce = false

local function destroyBox(player)

if debounce == false then

disabled.Value = true

script.RemoteEvent:FireClient(player)

print(“box smashed”)

end

end

ProximityPrompt.Triggered:Connect(function(player)

destroyBox(player)

end)

LocalScript (inside Tool)

local player = script.Parent.Parent.Parent
local Tool = script.Parent

Tool.Equipped:Connect(function()
for i,object in pairs(game.Workspace:GetDescendants()) do
if object.Name == “SmashPrompt” and object:IsA(“ProximityPrompt”) then
if object.Parent.Disabled.Value == false then
object.Enabled = true
end
end
end
end)

Tool.Unequipped:Connect(function()
for i,object in pairs(game.Workspace:GetDescendants()) do
if object.Name == “SmashPrompt” and object:IsA(“ProximityPrompt”) then
object.Enabled = false
end
end
end)

local RE = game.Workspace.Part.Script.RemoteEvent

RE.OnClientEvent:Connect(function()
for i,object in pairs(game.Workspace:GetDescendants()) do
if object.Name == “SmashPrompt” and object:IsA(“ProximityPrompt”) then
if object.Parent.Disabled.Value == true then
object.Enabled = false
end
end
end

Tool:Destroy()
end)

If this helped you, please mark it as the solution. Thanks!

P.S

Also, if you could help me because I forgot to make the code look like code on the DevForum? Thanks!

2 Likes

by doing that it’ll disable the prompt server wide, i suggest just using fireclient instead and disable the prompt on the client.(assuming your game isn’t single player) like what @poly456789 did

2 Likes