Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error with tool changing gui?

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

tool = script.Parent
plr = game.Players.LocalPlayer

mags = tool.Mags


tool.Equipped:connect(function(mse)
	mouse = mse
	mouse.Button1Down:connect(function()
		mags.Value = mags.Value -1
	if mags.Value == 5 then
	plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393235619"
		if mags.Value == 4 then
		plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393236237"
		if mags.Value == 3 then
		plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393236950"
		if mags.Value == 2 then
		plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393237626"
		if mags.Value == 1 then
		plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393238117"
		if mags.Value == 0 then
		plr.PlayerGui.PlayerHud.Ammoi.Image = "rbxassetid://393238639"
		end
		end
		end
		end
	end
	end
	end)
end)
tool.Unequipped:connect(function()
end)

Thanks

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.