I'm trying to make it so that if you press E, your stance will be passive, and if you press E again your stance will be aggressive. If I press E, the game successfully changes the status to "Passive", but if I press it again the status stays at "Passive".
local Player = game.Players.LocalPlayer local char = Player.Character or Player.CharacterAdded:Wait() local mode = Instance.new("StringValue", char.Torso) local mouse = Player:GetMouse() wait(1) mode.Name = "mode" local GUI = Instance.new("ScreenGui", Player.PlayerGui) -- //\\//ACTION TOGGLE VISUAL\\//\\ -- GUI.Name = "FDF" local PA = Instance.new("TextButton", GUI) PA.Size = PA.Size +UDim2.new(0,100,0,25) PA.Draggable = true PA.Text = "Status (E/<Attacks>)" PA.Position = PA.Position +UDim2.new(0,1250,0,25) script.Disabled = false -- VARIABLES ABOVE -- -- FUNCTION BELOW -- function onKeyDown(key) -- ACTION TOGGLE -- key = key:lower() if key == "e" then mode.Value = "Passive" PA.Text = mode.Value if mode.Value == "Passive" then char.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=700567206" char.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=700567206" char.Humanoid.WalkSpeed = 8 end -- ends 'if mode == passive' end -- ends if end -- ends function function onKeyDown2(key) -- ACTION TOGGLE -- if key == "e" then mode.Value = "Aggressive" PA.Text = mode.Value char.Humanoid.WalkSpeed = 25 end -- ends if end -- ends function mouse.KeyDown:connect(onKeyDown) mouse.KeyDown:connect(onKeyDown2)
Any solutions?
You should make sure you are using a local script on the client first. Then I would recommend you do something like this to get input for E:
local is_passive = true; local debounce = false; local function change_passive() if not debounce then debounce = true; if is_passive then --change the character accordingly is_passive = false; else --change the character accordingly is_passive = true; end wait(0.2); debounce = false; end end game:GetService("ContextActionService"):BindAction("change_mode", change_passive, false, Enum.KeyCode.E);
it is better to use ContextActionService and UserInputService for user input rather then the client's mouse. I hope this helps