My tool is not working at all

Hey I want To make A tool when activated It turns every part that touches the handle red after 10 seconds it stops. But it is not working at all. I used many scripts and none is working. This is the last script I used:

local Yes = false

if Yes == false then
	script.Parent.Orientation = Vector3.new(0,0,0)
end

if  Yes == true then
	script.Parent.Orientation = Vector3.new(-90, 0, 0)
	script.Parent.Touched:Connect(function(Part)
		 Part.BrickColor = BrickColor.Red()
	end)
end


script.Parent.Parent.Activated:Connect(function(act)
	Yes = true
	wait(10)
	Yes = false
end)
3 Likes

You’d need to disconnect that event once “Yes” becomes false else it’s always going to execute

2 Likes

actually it is not executing at all

1 Like
local Yes = false

coroutine.wrap(function()
      while task.wait() do
         if Yes == true then
            script.Parent.Orientation = Vector3.new(-90,0,0)
           else 
           script.Parent.Orientation = Vector3.new(0,0,0)
           end
      end
end)()
	script.Parent.Touched:Connect(function(Part)
		if Part:IsA("BasePart") and Yes then
         Part.BrickColor = BrickColor.Red()
       end
	end)


script.Parent.Parent.Activated:Connect(function(act)
	Yes = true
	wait(10)
	Yes = false
end)

I fixed your code, maybe this will work out for you

1 Like

It cannot detect when the Yes Value changes and What MP3Face said:

local Yes = false

local function ChangeYes()
    if Yes == false then
	  script.Parent.Orientation = Vector3.new(0,0,0)
    elseif Yes == true then
	   script.Parent.Orientation = Vector3.new(-90, 0, 0)
	   local conn = script.Parent.Touched:Connect(function(Part)
		   Part.BrickColor = BrickColor.Red()
           conn:Disconnect()
	   end)
    end
end

script.Parent.Parent.Activated:Connect(function(act)
	Yes = true
    ChangeYes()
	task.wait(10)
	Yes = false
    ChangeYes()
end)
2 Likes

This doesn’t listen to changes, this just checks it once then stops.
Either, wrap it in a loop or make a function to execute it:

local Yes
local function Check(val)
if val == false then
	script.Parent.Orientation = Vector3.new(0,0,0)
else
	script.Parent.Orientation = Vector3.new(-90, 0, 0)
	script.Parent.Touched:Connect(function(Part)
		 Part.BrickColor = BrickColor.Red()
	end)
end
end

script.Parent.Parent.Activated:Connect(function(act)
	Yes = true
Check(Yes)
	wait(10)
	Yes = false
Check(Yes)
end)
1 Like

what is that

the diffrece between task.wait and wait?

i am gonna try this script first

1 Like

yes there is a difference

1 Like

Basically, coroutine.wrap() will let the code inside of it run while still having the code under it run.

task.wait() is more efficient and precise.

1 Like

did you even type in the script when yes is true that happens?
in your script, it just said when val is true the thing happens but you didn’t do anything with the yes

and

1 Like

This activates the function with an Argument, the argument is “Yes” and the Function receives that and defines it as “val”

1 Like

Does any of the scripts that we gave you work

1 Like

val refers to what Yes has stored
image

1 Like

i tried it and that did not work at all

1 Like

What happens? Any error? Put some print statements to check too

1 Like

i put one it did not print anything

1 Like

Did the code that I sent you work

No, that script or code did not work either

1 Like

could you show me a picture of the tool and the objects inside it?

1 Like

this is all the parents and children

Tool)Tool >
UnionOrepration)Handle >
Script)Script

1 Like