local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Animate local Humanoid = player.Character:FindFirstChild('Humanoid') mouse.KeyDown:Connect(function(Key) Key = Key:lower() if Key == "c" then local Animation = Instance.new("Animation", player.Character) Animation.AnimationId = "rbxassetid://3555353330" Animate = Humanoid:LoadAnimation(Animation) Animate:Play() end end) if mouse.KeyDown:Connect(function(Key) Key = Key:lower() if Key == "c" then Animate:Destroy() end end end)
It keeps saying "expected ')' (to close '(' at line 15), got 'end'
Any ideas on how I could fix this or just fix the script in general? Its meant to be so every-time you press "c" your character crouches with a custom animation then when you press "c" again it stops the crouching animation and makes you stand like normal. I'm very NEW to scripting so sorry if I look stupid as hell.
edit
After looking at the comments I changed the script to use UserInputService but still have no idea
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Animate local Humanoid = player.Character:FindFirstChild('Humanoid') local UIS = game:GetService("UserInputService") UIS.InputBegan:connect(function(Input) local MouseInput = Input.UserInputType local KeyCode = Input.KeyCode if KeyCode == Enum.KeyCode.C then local Animation = Instance.new("Animation", player.Character) Animation.AnimationId = "rbxassetid://3555353330" Animate = Humanoid:LoadAnimation(Animation) Animate:Play() end end if KeyCode == Enum.KeyCode.C then Animate:Stop() end end)
Alright I know exactly whats up here.
You're trying to check if an event happens using if-statements.
Fortunately, you don't need to do that. When the event triggers, it will call the corresponding function without having to check it with an if-statement.
Let me show you what i mean
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Character = player.Character or player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local UIS = game:GetService("UserInputService") local debounce = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.C then if not debounce then debounce = true local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://3555353330" Animation.Parent = player.Character Animate = Humanoid:LoadAnimation(Animation) Animate:Play() else Animate:Stop() debounce = false end end end)
Okay so you're probably gonna say, "what the heck? this guy just completely rewrote my script", but I'll explain why.
Your script was based off of a false idea that you need to say someting like if event then
, so i just rewrote it to fix it up in that regard. I also removed all the deprecated code you were using and replaced it with the recommended versions.
Since you want to toggle the animations, you can use something called a debounce
, debounces have many use cases but for this case we're using it as basically an on/off switch for the animation.
Best of luck scripting, here are some sources that may help you out:
--Debounces
https://developer.roblox.com/en-us/articles/Debounce
--Whats deprecated code?
https://roblox.fandom.com/wiki/Deprecation
--Deprecated code article
https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296