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

Syntax error: expected ')' (to close '(' at line 81) got 'end' ?

Local Script In StarterCharacterScripts:

-- Services
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local tweenService = game:GetService("TweenService")
local playersService = game:GetService("Players")

-- Variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local pcButton = Enum.KeyCode.LeftControl --change ur key bind here
local xboxButton = Enum.KeyCode.ButtonL3

-- Settings
local normalSpeed = 16
local sprintSpeed = 26

local normalFov = 70
local sprintFov = 80

-- Boolean
local running = script:WaitForChild("Running")

-- Animation
local animation = script:WaitForChild("SprintAnim")
local sprintTrack = humanoid:LoadAnimation(animation)

-- // Functions

-- Camera tweening handler
local tween_fov = function(duration, value)
    
    local fov_tween = tweenService:Create(camera, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {FieldOfView = value})
    fov_tween:Play()
    
    return fov_tween
end

-- Input controller
function onKeyPress(actionName, userInputState, inputObject)
	function onKeyPress(actionName, userInputState, inputObject)
		if userInputState == Enum.UserInputState.Begin then
userInputService.InputBegan:Connect(function(input, processed)
    if input.KeyCode == (pcButton or xboxButton) and not processed then
        if humanoid.MoveDirection.Magnitude <= 0 then
            running.Value = true
            
            humanoid.WalkSpeed = sprintSpeed
        else
            running.Value = true
            
            humanoid.WalkSpeed = sprintSpeed
            sprintTrack:Play(0.25)
        end
    end
end)

userInputService.InputEnded:Connect(function(input, processed)
    if input.KeyCode == (pcButton or xboxButton) and not processed then
        running.Value = false
        
        humanoid.WalkSpeed = normalSpeed
        sprintTrack:Stop(0.25)
    end
end)

-- Field of view controller
running.Changed:Connect(function()
    if running.Value then
        tween_fov(0.5, sprintFov)
    elseif not running.Value then
        tween_fov(0.5, normalFov)
    end
end)

-- Main loop controller
runService.RenderStepped:Connect(function()
    if running.Value then
        
        -- Check if player is moving
        if humanoid.MoveDirection.Magnitude <= 0 then
            if sprintTrack.IsPlaying then
                sprintTrack:Stop(0.25)
            end
        elseif humanoid.MoveDirection.Magnitude > 0 then
            if not sprintTrack.IsPlaying then
                sprintTrack:Play(0.25)
            end
        end
        
        -- Check if player is jumping
        if humanoid.FloorMaterial == Enum.Material.Air then
            if sprintTrack.IsPlaying then
                sprintTrack:Stop(0.1)
            end
        elseif humanoid.FloorMaterial ~= Enum.Material.Air and humanoid.MoveDirection.Magnitude > 0 then
            if not sprintTrack.IsPlaying then
							sprintTrack:Play(0.25)
				end
				end
            end
        end
    end)
end
	end
	
	


game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.C)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626")

2 answers

✓ Accepted answer

What is :Disconnect. Explained in chat nobs.

-- Services
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local tweenService = game:GetService("TweenService")
local playersService = game:GetService("Players")

-- Variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local pcButton = Enum.KeyCode.LeftControl --change ur key bind here
local xboxButton = Enum.KeyCode.ButtonL3

-- Settings
local normalSpeed = 16
local sprintSpeed = 26

local normalFov = 70
local sprintFov = 80

-- Boolean
local running = script:WaitForChild("Running")

-- Animation
local animation = script:WaitForChild("SprintAnim")
local sprintTrack = humanoid:LoadAnimation(animation)

-- Connections
local inputBeganConnection
local inputEndedConnection

-- // Functions

-- Camera tweening handler
local tween_fov = function(duration, value)
  local fov_tween = tweenService:Create(camera, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {FieldOfView = value})
  fov_tween:Play()
  return fov_tween
end

-- Input controller
function onKeyPress(actionName, userInputState, inputObject)
  if userInputState == Enum.UserInputState.Begin then
    inputBeganConnection = userInputService.InputBegan:Connect(function(input, processed)
      if input.KeyCode == (pcButton or xboxButton) and not processed then
        if humanoid.MoveDirection.Magnitude <= 0 then
          running.Value = true

          humanoid.WalkSpeed = sprintSpeed
        else
          running.Value = true

          humanoid.WalkSpeed = sprintSpeed
          sprintTrack:Play(0.25)
        end
      end
    end)
    
    inputEndedConnection = userInputService.InputEnded:Connect(function(input, processed)
      if input.KeyCode == (pcButton or xboxButton) and not processed then
        running.Value = false
        humanoid.WalkSpeed = normalSpeed
        sprintTrack:Stop(0.25)
      end
    end)
  else
    inputBeganConnection:Disconnect()
    inputEndedConnection:Disconnect()
  end
end

-- Field of view controller
running.Changed:Connect(function()
  if running.Value then
    tween_fov(0.5, sprintFov)
  elseif not running.Value then
    tween_fov(0.5, normalFov)
  end
end)

-- Main loop controller
runService.RenderStepped:Connect(function()
  if running.Value then
    -- Check if player is moving
    if humanoid.MoveDirection.Magnitude <= 0 then
      if sprintTrack.IsPlaying then
        sprintTrack:Stop(0.25)
      end
    elseif humanoid.MoveDirection.Magnitude > 0 then
      if not sprintTrack.IsPlaying then
        sprintTrack:Play(0.25)
      end
    end

    -- Check if player is jumping
    if humanoid.FloorMaterial == Enum.Material.Air then
      if sprintTrack.IsPlaying then
        sprintTrack:Stop(0.1)
      end
    elseif humanoid.FloorMaterial ~= Enum.Material.Air and humanoid.MoveDirection.Magnitude > 0 then
      if not sprintTrack.IsPlaying then
        sprintTrack:Play(0.25)
      end
    end
  end
end)

game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.C)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626")

Hiya,

I've looked over your code and I think your error is are lines 108 and 109

  • It looks like you have an extra end block on line 109
  • and you don't have a ) to close the end on line 108

(edit)

  • you don't need the ) on line 107
  • you've copy pasted the same function into itself on line 44 & 45

This is what I've got after editing all those issues out

-- Services
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local tweenService = game:GetService("TweenService")
local playersService = game:GetService("Players")

-- Variables
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local pcButton = Enum.KeyCode.LeftControl --change ur key bind here
local xboxButton = Enum.KeyCode.ButtonL3

-- Settings
local normalSpeed = 16
local sprintSpeed = 26

local normalFov = 70
local sprintFov = 80

-- Boolean
local running = script:WaitForChild("Running")

-- Animation
local animation = script:WaitForChild("SprintAnim")
local sprintTrack = humanoid:LoadAnimation(animation)

-- // Functions

-- Camera tweening handler
local tween_fov = function(duration, value)
    local fov_tween = tweenService:Create(camera, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {FieldOfView = value})
    fov_tween:Play()
    return fov_tween
end

-- Input controller
function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        userInputService.InputBegan:Connect(function(input, processed)
        if input.KeyCode == (pcButton or xboxButton) and not processed then
            if humanoid.MoveDirection.Magnitude <= 0 then
                running.Value = true

                humanoid.WalkSpeed = sprintSpeed
            else
                running.Value = true

                humanoid.WalkSpeed = sprintSpeed
                sprintTrack:Play(0.25)
            end
        end
    end
end)

userInputService.InputEnded:Connect(function(input, processed)
    if input.KeyCode == (pcButton or xboxButton) and not processed then
        running.Value = false
        humanoid.WalkSpeed = normalSpeed
        sprintTrack:Stop(0.25)
    end
end)

-- Field of view controller
running.Changed:Connect(function()
    if running.Value then
        tween_fov(0.5, sprintFov)
    elseif not running.Value then
        tween_fov(0.5, normalFov)
    end
end)

-- Main loop controller
runService.RenderStepped:Connect(function()
    if running.Value then
        -- Check if player is moving
        if humanoid.MoveDirection.Magnitude <= 0 then
            if sprintTrack.IsPlaying then
                sprintTrack:Stop(0.25)
            end
        elseif humanoid.MoveDirection.Magnitude > 0 then
            if not sprintTrack.IsPlaying then
                sprintTrack:Play(0.25)
            end
        end

        -- Check if player is jumping
        if humanoid.FloorMaterial == Enum.Material.Air then
            if sprintTrack.IsPlaying then
                sprintTrack:Stop(0.1)
            end
        elseif humanoid.FloorMaterial ~= Enum.Material.Air and humanoid.MoveDirection.Magnitude > 0 then
            if not sprintTrack.IsPlaying then
                sprintTrack:Play(0.25)
            end
        end
    end
end)

game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.C)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626")

(end edit)

Hopefully this resolves your issue.

6 comments

0

still doesnt work

0

Does it still provide the same error?

0

also; you dont need the ) on line 107, this could be causing the error.

0

also on line 44 & 45 you're calling the same function inside the function?

0

i pasted the code you sent

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