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

Error with tool changing gui?

Asked by
adatax 5
9 years ago

Idea The goal of this tool is so every time the player clicks a value in the tool goes down by one, and every time it goes down, an imagelabel also changes to correlate.

Problem The only issue with this script is that it works once. the player clicks once, the gui changes to correlate and then nothing else. when you click again the value goes down but the gui remains the same. I get no errors.

Code

01tool = script.Parent
02plr = game.Players.LocalPlayer
03 
04mags = tool.Mags
05 
06 
07tool.Equipped:connect(function(mse)
08    mouse = mse
09    mouse.Button1Down:connect(function()
10        mags.Value = mags.Value -1
11    if mags.Value == 5 then
12    plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393235619"
13        if mags.Value == 4 then
14        plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393236237"
15        if mags.Value == 3 then
View all 32 lines...

Thanks

1 answer

Log in to vote
0
Answered by 9 years ago

Nested conditions

Your conditions are nested, which is bad because if v == 4 then v ~= 3. Likewise, if the outermost condition does not evaluate to true, you're never going to reach the inner conditions.

Your solution is to use an elseif statement instead of a nested if statement

Ad

Answer this question