Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is script falsely renaming a tool?

Ovations, everyone. I was writing a script, where it renames your tool when you touch something. My tool is called Mop and it is still renaming it to Mop | 3/3 .. What is the problem with my script? I would be glad if anyone could help me.

script.Parent.Touched:connect(function(h)
 if h.Parent.Name == "Mop" then 
		h.Parent.Name = "Mop | 1/3"
	elseif h.Parent.Name == "Mop | 1/3" then 
		h.Parent.Name = "Mop | 2/3"
	elseif h.Parent.Name == "Mop | 2/3" then 
		h.Parent.Name = "Mop | 3/3"
end
end)

Every single help is appreciated, thank you!

1 answer

Since .Touched events fire pretty fast youll need a debounce and TouchEnded.

local deb
script.Parent.Touched:connect(function(h)
	if not deb then
		deb = true
 		if h.Parent.Name == "Mop" then 
        		h.Parent.Name = "Mop | 1/3"
    		elseif h.Parent.Name == "Mop | 1/3" then 
        		h.Parent.Name = "Mop | 2/3"
    		elseif h.Parent.Name == "Mop | 2/3" then 
       			h.Parent.Name = "Mop | 3/3"
		end
	end
end)
script.Parent.TouchEnded:Connect(function(h)
	if string.match(h.Parent.Name, "^Mop") then --checks if the tool's name starts with mop
		deb = false
	end
end)

5 comments

0

It still names it "Mop | 3/3" when it should call it "Mop | 1/3" as the tool is called "Mop". Your answer is appreciated tho!

0

have you tried placing a print in .Touched and .TouchEnded?

0

Yep, they both printed. It gotta be an issue with the renaming.

0

how often did they print

0

Really often, I think I found the problem btw. It goes trough every step so fast that I cannot even see it. Like, it renames it to 1/3 but then it renames it to 2/3 so fast that I cannot see it.

This discussion is preserved as it was. New answers, comments, and votes are closed.