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

getting an Expected ')' (to close '(' at line 3), got 'end' error when i shouldnt be?

Asked by
adgaz 0
3 years ago

Heres my code: (it should work can someone tell me why im getting this error: 00:26:27.435 Model.MainModule:41: Expected ')' (to close '(' at line 3), got 'end' - Studio

local runService = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local chr = plr.Character
local humrootpart = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local cam = workspace.Camera

local tiltSpeedZ = 0.1
local bobbingSpeed = 0.1

local tilt = 0
local sinValue = 0


function lerp(a, b, t)
    return a + (b - a) * t
end

function calculateSine(speed, intensity)
    sinValue += speed 
    if sinValue > (math.pi * 2) then sinValue = 0 end
    local sineY = intensity * math.sin(2 * sinValue)
    local sineX = intensity * math.sin(sinValue)
    local sineCFrame = CFrame.new(sineX, sineY, 0)
    return sineCFrame
end

local previousSineX = 0
local previousSineY = 0
runService.RenderStepped:Connect(function(dt)
    local movementVector = cam.CFrame:vectorToObjectSpace(humrootpart.Velocity / math.max(hum.WalkSpeed, 0.01))
    local speedModifier = (hum.WalkSpeed / 16)
    tilt = math.clamp(lerp(tilt, movementVector.X * tiltSpeedZ, 0.1), -0.25, 0.1) 

    local sineCFrame = calculateSine(bobbingSpeed * speedModifier, movementVector.Z * speedModifier)
    local lerpedSineX = lerp(previousSineX, sineCFrame.X, 0.1)
    local lerpedSineY = lerp(previousSineY, sineCFrame.Y, 0.1)

    cam.CFrame *= CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0)
    previousSineX = lerpedSineX
    previousSineY = lerpedSineY
end)

1 answer

Log in to vote
0
Answered by 3 years ago
local runService = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local chr = plr.Character
local humrootpart = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local cam = workspace.Camera

local tiltSpeedZ = 0.1
local bobbingSpeed = 0.1

local tilt = 0
local sinValue = 0


function lerp(a, b, t)
    return a + (b - a) * t
end

function calculateSine(speed, intensity)
    sinValue += speed -- Error here
    if sinValue > (math.pi * 2) then sinValue = 0 end
    local sineY = intensity * math.sin(2 * sinValue)
    local sineX = intensity * math.sin(sinValue)
    local sineCFrame = CFrame.new(sineX, sineY, 0)
    return sineCFrame
end

local previousSineX = 0
local previousSineY = 0
runService.RenderStepped:Connect(function(dt)
    local movementVector = cam.CFrame:vectorToObjectSpace(humrootpart.Velocity / math.max(hum.WalkSpeed, 0.01))
    local speedModifier = (hum.WalkSpeed / 16)
    tilt = math.clamp(lerp(tilt, movementVector.X * tiltSpeedZ, 0.1), -0.25, 0.1) 

    local sineCFrame = calculateSine(bobbingSpeed * speedModifier, movementVector.Z * speedModifier)
    local lerpedSineX = lerp(previousSineX, sineCFrame.X, 0.1)
    local lerpedSineY = lerp(previousSineY, sineCFrame.Y, 0.1)

    cam.CFrame *= CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0) --Error Here
    previousSineX = lerpedSineX
    previousSineY = lerpedSineY
end)

Im not too sure what you are trying to do in those two parts that I marked but in lua when trying to add something to a value you must do something like "sinValue = sinValue + speed"

0
For the second one you would do "cam.CFrame = cam.CFrame * CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0) tightanfall 110 — 3y
0
No, you can do +=. Example: local num1 = 5; num1 += 6; print(num1) the result is 11 MarkedTomato 810 — 3y
0
So it adds the value and sets the value MarkedTomato 810 — 3y
0
You can't do that with lua. You have to do it separately ie: "sinValue = sinValue + speed" this is the only way to add to a value in script. tightanfall 110 — 3y
0
If you would like your script to work, i suggest following my instructions. tightanfall 110 — 3y
Ad

Answer this question