Im making a gun for myself and have a mode setup however the piece of my code that should switch the mode / value of the StringValue of my gun doesn't seem to want to change it, is this because its a LocalScript or have I just messed up the coding help please. The code includes when I repeatedly press the key "z" it cycles through modes but it stays on the damaging mode.
local mode = script.Parent.Modes.Mode.Value if key == "z" and reloading == false and firing == false then if mode == "Damaging" then mode = "Stun" print("Stun") elseif mode == "Stun" then mode = "Poison" print("Poison") elseif mode == "Poison" then mode = "Damaging" print("Damaging") else mode = nil end end
You're only getting the mode value once and not setting the value correctly.
If you read the mode
variable whenever you press 'z', and set the value correctly, this should fix the problem.
if key == "z" and reloading == false and firing == false then local mode = script.Parent.Modes.Mode if mode.Value == "Damaging" then mode.Value = "Stun" print("Stun") elseif mode.Value == "Stun" then mode.Value = "Poison" print("Poison") elseif mode.Value == "Poison" then mode.Value = "Damaging" print("Damaging") else mode.Value = "" end end
(Also I see you're getting the key "z" as a string, but it's better practice to be using UserInputService)