Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can somebody debug this script?

Asked by 8 years ago

I am trying to script a script that when you clicked on it, the door un-Cancollided and make a person come in. <-- That part works.

When the button is pressed, the color of the button changed to red then it changes to green. This part doesn't work..Don't know why?

I tested this script multiple times and still doesn't work.

function onClicked()
             script.Parent.Parent.Door.Transparency= 0.5
             script.Parent.Parent.Door.CanCollide= true 
             wait(0.1)
             script.Parent.Parent.Button.Color = 255, 0, 0 --Button turns to the color red
             wait(0.9)
             script.Parent.Parent.Door.Transparency= 0.4
             script.Parent.Parent.Door.CanCollide= true 
             wait(0.9)
             script.Parent.Parent.Door.Transparency= 0.2
             script.Parent.Parent.Door.CanCollide= false --Make a person(s) can go through the door
             wait(3)
             script.Parent.Parent.Door.Transparency= 0
             script.Parent.Parent.Door.CanCollide= true --Can't make person(s) go in the door anymore.
             wait(0.1)
             script.Parent.Parent.Button.Color= 0, 255, 0 --Button turns to the color green
end
 script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thx!

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

You can't change the color like that. You gave it three numbers, but that won't work. You have to use Color3.new. So let's try that:

script.Parent.Parent.Button.Color = Color3.new(255, 0, 0)

But this still won't work, because Color3.new can't have a number between 0 and 255. It has to have a decimal between 0 and 1. A common way to achieve this is just to take a number up to 255, then divide it by 255, giving you a number between 0 and 1.

But in your case, 255/255 will just equal 1, so we can just use that.

script.Parent.Parent.Button.Color = Color3.new(1, 0, 0)

Of course, you can't do this if Button is a brick, but I assumed it was a SurfaceGui or something.

Ad

Answer this question