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

Help me with this if statement please?

Asked by 10 years ago

So, I was trying out if statements(nothing too long) and something didn't work. Please help, It's the first script I make that doesn't work at all :(

if game.Workspace.Part.Transparency == 0 then
    print"It is not transparent"
elseif game.Workspace.Part.Transparency == 0.5 then
    print"It is transparent"
elseif game.Workspace.Part.Transparency == 0.6 then
    print"It is slightly more transparent"
end

When I make the transparency of the part 0.5, it prints "it is transparent" into the Output. However, when I make the transparency of the part 0.6, the system doesn't print "it is slightly more transparent" into the Output. I'm not sure if there's something wrong with my indenting, but I would appreciate it if someone helped me with this predicament.?

I fixed the problem by changing the second elseif to:

elseif Game.Workspace.Part.Transparency > 0.5 then print("it is slightly more transparent")

When I did this, the system printed "it is slightly more transparent" but I want to know why it wasn't working the first time.?

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, you need to trigger when to run that line of code. You could put it in a loop, but that would simply spam your Output. I recommend using the Changed event to resolve your issue.

Part = game.Workspace.Part

Part.Changed:connect(function()
    if game.Workspace.Part.Transparency == 0 then
        print"It is not transparent"
    elseif game.Workspace.Part.Transparency == 0.5 then
        print"It is transparent"
    elseif game.Workspace.Part.Transparency == 0.6 then
        print"It is slightly more transparent"
    end
end)
Ad

Answer this question