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

What went wrong?

I am new at scripting to so I decided I would try to make a code where when you touch part, it's collide is false for 3 seconds then returns to normal. Also when the brick is in "Can't collide" the color of part2 changes as well. So can anyone point out the error?

Base = Script.Parent.Parent.Part
Colors = game.Workspace.Part2

function onTouched (hit)
	Base.Transparency = 1
	Base.CanCollide = false
	wait(3)
	Base.Transparency = 0.3
	Base.CanCollide = true
end

Script.Parent.Touched:connect(onTouched)

if Base.CanCollide = false then
	Colors.BrickColor = Brightgreen
end

if Base.CanCollide = true then
	Colors.BrickColor = Brightred
end

3 answers

✓ Accepted answer

USerOnly16Characters Was Right Half way as well, He made a simple spelling error, That I will fix for him.

Base = Script.Parent.Parent.Part
Colors = game.Workspace.Part2

function onTouched (hit)
    Base.Transparency = 1
    Base.CanCollide = false
    wait(3)
    Base.Transparency = 0.3
    Base.CanCollide = true
end

Script.Parent.Touched:connect(onTouched)

if Base.CanCollide == false then--When your checking something you must have two equals
    Colors.BrickColor = BrickColor.new("Bright green")--Had 'Brighten green'
end

if Base.CanCollide == true then--When your checking something you must have two equals
    Colors.BrickColor = BrickColor.new("Bright red")
end

In line 15 and 19 you made a very simple mistake.

Base = Script.Parent.Parent.Part
Colors = game.Workspace.Part2

function onTouched (hit)
    Base.Transparency = 1
    Base.CanCollide = false
    wait(3)
    Base.Transparency = 0.3
    Base.CanCollide = true
end

Script.Parent.Touched:connect(onTouched)

if Base.CanCollide == false then--When your checking something you must have two equals
    Colors.BrickColor = BrickColor.new("Bright green")
end

if Base.CanCollide == true then--When your checking something you must have two equals
    Colors.BrickColor = BrickColor.new("Bright red")
end

1 comment

0

If I solved your problem I would appreciate if you could accept my answer.

You can easily make your brick CanCollide turn false with a WAY easier script.~~~~~~~~~~~~~~~~~ local brick = workspace.Brick function onTouched(hit) brick.CanCollide = false wait(3) brick.CanCollide = true end brick.Touched:connect(onTouched)


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