Glitch with tools

Example: https://gyazo.com/b9178307f2fd4321bb6c78bd1bc56930

(Watch example for context)
It’s hard to explain, but whenever I switch tools and feed the campfire with a previously switched tool, the other previously switched tools would be used to feed the campfire also (In short: I want the tool that i’m holding be fed to the campfire)

My script in the tools

--//Functions//--
local Tool = script.Parent

local Campfire = workspace.Campfire
local Prompt = Campfire.Fire.Attachment.ProximityPrompt

local RS = game:GetService("ReplicatedStorage")

--//Main//--
Tool.Equipped:Connect(function()
	Prompt.Enabled = true

	Prompt.Triggered:Connect(function()
		Prompt.Enabled = false

		workspace.Campfire.Fire.Value.Value = workspace.Campfire.Fire.Value.Value + math.random(script.Min.Value, script.Max.Value)
		workspace.Campfire.Fire.Heal:Play()
		
		script.Parent:Destroy()
	end)
end)

Tool.Unequipped:Connect(function()
	Prompt.Enabled = false
end)

I assume it due to the fact that you’re connecting the Prompt.Triggered event inside the Tool.Equipped event. This means that every time you equip a tool, a new connection is made to the Prompt.Triggered event. When the prompt is triggered, all of these connections are fired, which results in all of the equipped tools being used to feed the campfire.

You should try moving the connection outside of the Tool.Equipped event, and we should also check if the tool is currently equipped when the prompt is triggered, like so:

--//Functions//--
local Tool = script.Parent

local Campfire = workspace.Campfire
local Prompt = Campfire.Fire.Attachment.ProximityPrompt

local RS = game:GetService("ReplicatedStorage")

--//Main//--
local toolEquipped = false

Tool.Equipped:Connect(function()
    Prompt.Enabled = true
    toolEquipped = true
end)

Tool.Unequipped:Connect(function()
    Prompt.Enabled = false
    toolEquipped = false
end)

Prompt.Triggered:Connect(function()
    if toolEquipped then
        Prompt.Enabled = false

        workspace.Campfire.Fire.Value.Value = workspace.Campfire.Fire.Value.Value + math.random(script.Min.Value, script.Max.Value)
        workspace.Campfire.Fire.Heal:Play()
        
        script.Parent:Destroy()
    end
end)

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