My tool is not working at all

local Activate: thread = nil
local OldColors = {}
local PartsWaiting = {}
local Tool: Tool = script.Parent
local TouchCooldown: boolean = false
local Touched: thread = nil

function UnwrappedTouched(Part: BasePart, ShouldWait: boolean)
	if Part and TouchCooldown == false and Tool.Enabled == false and not PartsWaiting[Part] then
		local OldColor: Color3 = Part.Color
		TouchCooldown = true
		PartsWaiting[Part] = true
		table.insert(OldColors, {Object = Part, Color = Part.Color})
		Part.Color = Color3.new(1, 0, 0)
		Part.Orientation += Vector3.new(-90, 0, 0)
		if ShouldWait == true then
			task.wait(1 / 4)
			Part.Color = OldColor
		end
		TouchCooldown = false
		task.wait(1 / 4)
		Part.Color = OldColor
	end
end

function UnwrappedActivated()
	if Tool.Enabled == true then
		Tool.Enabled = false
		for index, object in ipairs(Tool.Handle:GetTouchingParts()) do
			Touched = coroutine.create(UnwrappedTouched)
			coroutine.resume(Touched, object, false)
		end
		task.wait(10)
		for index, object in ipairs(OldColors) do
			object.Object.Color = object.Color
		end
		table.clear(PartsWaiting)
		table.clear(OldColors)
		Tool.Enabled = true
		TouchCooldown = false
	end
end

Tool.Handle.Touched:Connect(function(Part: BasePart)
	Touched = coroutine.create(UnwrappedTouched)
	coroutine.resume(Touched, Part, true)
end)
Tool.Activated:Connect(function()
	Activate = coroutine.wrap(UnwrappedActivated)
	Activate()
end)

What I have at the moment, the tool is activated and will rotate parts it touches. The rotated parts cannot be rotated again until the 10 seconds have passed.

bruh it rotated the whole baseplate!
I dont want that to happen!
look, when I activate the tool the ONLY THe Handle is rotated and not other parts, So The part that Touches The handle gets painted red. So it will only work 10 seconds, That is what i want

Alright, thatā€™s the explaination I needed. I should be able to do that easily when I get the chance.

1 Like

I donā€™t think anyone has mentioned this in this thread, but did you check to see if the Handle has the CanTouch property set to true? If itā€™s not, touched events will not execute. Your code could be running perfectly fine, itā€™s just not activating if CanTouch is false under the Handles Properties.

While a lot of people in this thread have been overcomplicating the script, it could have been working just fine from the get go. Thereā€™s been many instances where I forget to check CanTouch or when Iā€™m using a certain plugin in which disables CanTouch by default. You have to make sure all your properties are configured correctly.

1 Like

i think i checked before, it was set to true, but let me make sure it is still true

Make sure your using a local script not a script.

why local script?
if I use a local script then if I use the tool it will only show for the player who used it.

I am using a script and will use a script

what are you even talking about?

Okay, this thread is long and confusing.

To sum it up, OP seems to want a painting tool that only works for 10 seconds at a time.

They want the tool to be rotated -90Ā° on the x-axis when activated and turn whatever part it touches red.

I have questions about this behavior which I will list here:

  • Does the painted part return to the original color? If so, when?

  • Are you actually trying to make a painting tool? Or is it something else?

Once I know the answers, I will come up with a script that behaves correctly.

1 Like

no, the painted part is painted and will be painted. It will not return to the original color.

yes, i am making a painting tool. Nothing else.

of course

I would try using a BoolValue that detects if it is true or false (yes/no)

1 Like

Questions were answered!

I suggest this:

  • Instead of touching a part to paint it, a user can instead click on the part which is way less clunky

If the OP wants the original behavior, Iā€™ll do that.

1 Like

You shouldnā€™t be writing full scripts for users on the forum, especially under this category.

All you have to do is point them in the right direction. Tell them what they need to do, give them code snippets for examples, and youā€™re set. If the OP is not competent enough to fulfill the task, they might have to read over the DevHub as well as watching Video tutorials if thatā€™s their style.

To the OP,

If youā€™re making this system, I recommend using TweenService to rotate the handles Orientation property, not CFrame as that will affect position too.

Using bools would be most efficient in terms of making it so the paint tool doesnā€™t fire a million times in one second.

yeah nice suggestion it is good

i want to do both.

just tell me how to do both

I might choose one of them

Yeah, Iā€™ll be doing that after this is finished. Nobody learns anything if you just write a script for them to use.

2 Likes

When I have access to my PC again, Iā€™ll start testing some solutions.

1 Like

access to the pc? what do you mean arenā€™t you on pc?

Not at the moment, Iā€™m currently busy right now but I can look at devforum for a bit.

1 Like