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

Laser Click Detector Switch Not Working, Why?

Asked by 6 years ago
Edited 6 years ago

I made a part in this location game.Workspace

I called it TheSwitch and added a few other objects including a ClickDetector and a decal

When you click it, it's supposed to change the value of a number value which would get involved in a later script that isn't in this question, the image, and the brick color. It's not working because there's a supposed error in the first line in the start of the if statement claiming that = should be replaced with then but I don't know what to replace .Value = '1' with.

The Script

local function onMouseClick(player)
    if game.Workspace.Value.Value then 
        game.Workspace.Value.Value = 0  
        game.Workspace.TheSwitch.Decal.Texture = 'rbxgameasset//images/CoolingTemp'
        game.Workspace.Value.Value = 1
        game.Workspace.TheSwitch.BrickColor = 'Lime Green'

    else
        game.Workspace.TheSwitch.Decal.Texture = 'rbxgameasset//images/AtomTechHeatError'
        game.Workspace.Value.Value = 0
        game.Workspace.TheSwitch.BrickColor = 'Really Red'
    end


end
clickDetector.MouseClick:connect(onMouseClick)

1
if game.Workspace.Value.Value == '0' then blowup999 659 — 6y

1 answer

Log in to vote
0
Answered by
B_Iu 31
6 years ago
Edited 6 years ago

Hey there. As you can see, I have made quite of a lot of changes. First of all, you were trying to make the function a value with local before it. for functions, just use function.

Next, I saw that you need to make the values of 0, 1, and 1 needed to be VALUES, not strings. (eg. "example" or 'example')

Also, when you are seeing if the value is equal to a certain number, you need to use "==" instead of "=".

You had some issues with the decal changes, you need to make it a Roblox asset with the id of that asset. You need to replace CoolingTempAssetIDhere and ErrorAssetIDhere with the asset id of the images. To find those, click on your decal, look at the numbers at the top and copy and paste them. An example of an asset id would be 12345678

So all that aside, here is the script. If you didn't read the above already, please do, it is very important.

function onMouseClick(player)
    if game.workspace.Value.Value == 0 then --start of the if statement
        game.workspace.TheSwitch.Decal.Texture = "http://www.roblox.com/asset/?id=CoolingTempAssetIDhere"
        game.workspace.Value.Value = 1
        game.workspace.TheSwitch.BrickColor = BrickColor.new("Lime green")

    else
        game.workspace.TheSwitch.Decal.Texture = "http://www.roblox.com/asset/?id=ErrorAssetIDhere"
        game.workspace.Value.Value = 1
        game.workspace.TheSwitch.BrickColor = BrickColor.new("Really red")
    end


end
script.parent.MouseClick:connect(onMouseClick)

If this script doesn't work, tell me what the error is in the Output.

Ad

Answer this question