Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
OFF_S4LE 127
3 years ago

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

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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")

Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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.

0
still doesnt work OFF_S4LE 127 — 3y
0
Does it still provide the same error? loowa_yawn 383 — 3y
0
also; you dont need the ) on line 107, this could be causing the error. loowa_yawn 383 — 3y
0
also on line 44 & 45 you're calling the same function inside the function? loowa_yawn 383 — 3y
View all comments (2 more)
0
i pasted the code you sent OFF_S4LE 127 — 3y

Answer this question