01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local Animate |
04 | local Humanoid = player.Character:FindFirstChild( 'Humanoid' ) |
05 |
06 | mouse.KeyDown:Connect( function (Key) |
07 | Key = Key:lower() |
08 | if Key = = "c" then |
09 | local Animation = Instance.new( "Animation" , player.Character) |
10 | Animation.AnimationId = "rbxassetid://3555353330" |
11 | Animate = Humanoid:LoadAnimation(Animation) |
12 | Animate:Play() |
13 | end |
14 | end ) |
15 | if mouse.KeyDown:Connect( function (Key) |
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
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local Animate |
04 | local Humanoid = player.Character:FindFirstChild( 'Humanoid' ) |
05 | local UIS = game:GetService( "UserInputService" ) |
06 |
07 | UIS.InputBegan:connect( function (Input) |
08 | local MouseInput = Input.UserInputType |
09 | local KeyCode = Input.KeyCode |
10 |
11 | if KeyCode = = Enum.KeyCode.C then |
12 | local Animation = Instance.new( "Animation" , player.Character) |
13 | Animation.AnimationId = "rbxassetid://3555353330" |
14 | Animate = Humanoid:LoadAnimation(Animation) |
15 | Animate:Play() |
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
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local Character = player.Character or player.CharacterAdded:Wait() |
04 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
05 | local UIS = game:GetService( "UserInputService" ) |
06 |
07 | local debounce = false |
08 | UIS.InputBegan:Connect( function (Input) |
09 | if Input.KeyCode = = Enum.KeyCode.C then |
10 | if not debounce then |
11 | debounce = true |
12 | local Animation = Instance.new( "Animation" ) |
13 | Animation.AnimationId = "rbxassetid://3555353330" |
14 | Animation.Parent = player.Character |
15 | Animate = Humanoid:LoadAnimation(Animation) |
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