How would I prevent this firing multiple times?

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!
    I want the text to change once
  2. What is the issue? Include screenshots / videos if possible!
    Currently it changes as many times as the player has equipped the tool
  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    Tried storing tools in a table but got confused and can’t find anything similar
    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!
local cdscreen = game.ReplicatedStorage.GUI.Core.ToolInfo:Clone()
        cdscreen.Parent = plr.PlayerGui
        local cdtext = cdscreen.CooldownInfo.CDText 
        
        local currenttool
        local alreadyfound = {}
        
        chr.ChildAdded:Connect(function(tool)
            
            if tool:IsA("Tool") then
                currenttool = tool
                plr.PlayerGui:WaitForChild("ToolInfo").CooldownInfo.Visible = true
                if tool == currenttool then
                    local cooldown : BoolValue = tool:FindFirstChild("Cooldown")
                    if cooldown then
                        
                        
                        cdtext.Visible = true
                        cdtext.Parent.Visible = true

                        if cooldown.Value == true then
                            cdtext.Text = "On Cooldown"
                        else
                            cdtext.Text = "Ready to use"
                        end

                        cooldown:GetPropertyChangedSignal("Value"):Connect(function()
                            --currently fires as many times as the player has equipped the tool
                            if currenttool == tool then
                                if cooldown.Value == true then
                                    cdtext.Text = "On Cooldown"
                                else
                                    cdtext.Text = "Ready to use"
                                end
                            end

                        end)



                    else
                        cdtext.Parent.Visible = false
                        cdtext.Visible = false
                    end
                end

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

Are you trying to write a string once someone equips a tool?

basically, each tool with a cooldown on it has a boolean object on it, i just want to make it so when you equip one, the gui displaying whether it is or is not on cooldown shows up and changes when the value changes, so far this works but changes it as many times as the player has re-equipped the same tool.

so as i understand it glitches out and the Tools’ cooldowns start to intersect with eachother?

You need a cooldown task.wait(whatever cooldown time you choose) in your code, otherwise the boolean changes instantly from true to false (or false to true, your code doesn’t say which one it is).

1 Like

no, let’s say i put a print statement in the propertychanged event, it checks the value being changed and for every time the tool is re-equipped, prints it. so if i equipped the tool 8 times it would print 8 timess

Do you want it to print only 1 time?

I think the problem is that you’re Connecting a new :GetPropertyChangedSignal("Value") everytime a tool is equipped, and these connections/events or whtvr you call them are still running in the background.

You could store these connections in a global variable and when a tool is equipped disconnect whatever connection was stored previously if there is any kinda like this

local cdscreen = game.ReplicatedStorage.GUI.Core.ToolInfo:Clone()
cdscreen.Parent = plr.PlayerGui
local cdtext = cdscreen.CooldownInfo.CDText 

local currenttool
local alreadyfound = {}
local Connection --creating the variable for storing these connections

chr.ChildAdded:Connect(function(tool)

	if tool:IsA("Tool") then
		if Connection then--checking if there is a connection to disconnect it
			Connection:Disconnect()--disconnecting the connection
		end
		currenttool = tool
		plr.PlayerGui:WaitForChild("ToolInfo").CooldownInfo.Visible = true
		if tool == currenttool then
			local cooldown : BoolValue = tool:FindFirstChild("Cooldown")
			if cooldown then


				cdtext.Visible = true
				cdtext.Parent.Visible = true

				if cooldown.Value == true then
					cdtext.Text = "On Cooldown"
				else
					cdtext.Text = "Ready to use"
				end
				--Here we store the connection
				Connection = cooldown:GetPropertyChangedSignal("Value"):Connect(function()
					if currenttool == tool then
						if cooldown.Value == true then
							cdtext.Text = "On Cooldown"
						else
							cdtext.Text = "Ready to use"
						end
					end

				end)



			else
				cdtext.Parent.Visible = false
				cdtext.Visible = false
			end
		end



	end

end)

Let me know if there is any new problem or any doubt that you have.

1 Like

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