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

why does this script not check the value correctly?

Asked by 8 years ago
if mouse.Target.BrickColor == BrickColor.new("New Yeller") and player.leaderstats.level.Value >= 1 then
                    thing()
                elseif mouse.Target.BrickColor == BrickColor.new("Deep orange") and player.leaderstats.level.Value >= 5 then
                    thing()
elseif player.leaderstats.level.Value > 5 and mouse.Target.BrickColor == BrickColor.new("Deep orange") then
    print'no level for you' -- this never happens
                elseif mouse.Target.BrickColor == BrickColor.new("Lime green") and player.leaderstats.level.Value >= 10 then
                    thing()
end

where mouse = game.Players.LocalPlayer:GetMouse() and thing() is a function I KNOW that its something with the if's or the values being dumb, because i set my level val to 1, and it still didn't print anything when i moved my mouse over it.

basically, this is supposed to make it so that if the mouses target is say, green, and the player's leaderstat value 'level' is not greater than, or equal to ten, but for some reason, it's not printing anything when the mouses target is deep orange.

the level requirments are because why not?

the color is an identifier, both with sight and script.

1 answer

Log in to vote
0
Answered by
Kryddan 261 Moderation Voter
8 years ago

An if statement that has more options or whatever you gonna call it. The if statement runs through every option until it finds an option that is valid, then it stops. Likewise with your code, you have two options which basically is the same.

The second options checks if your mouse is hovering over an object that has the brick color of "deep orange" and if your level is equal to or greater than 5. The third option where you said the problem where located because it doesn't print: "no level for you". It checks if the players mouse is hovering over an object with the brick color of "deep orange", the same as the second option, nothing wrong with that. But here is the problem, it also checks if the player's level is greater than 5, as I said earlier the if statement runs through all options until it finds a valid one (or if there is no valid option) then it stops. The second option becomes valid before the third one always, because it checks if the player's level is either equal to or greater than 5 while the third option only checks if it's greater than 5.

I don't know if this made sense to you so if it didn't just comment below and I can try to make it even more clear.

Ad

Answer this question