Really confused on what's going on here, if you guys could help me how to fix this issue it would be really appreciated.
local mouse=game.Players.LocalPlayer:GetMouse() script.Parent:WaitForChild("src3") src=script.Parent.src3.Value mouse.KeyDown:connect(function(key) if key=="h" and src.Parent.Parent.Body.headlights.on.Value == true then src.Parent.Parent.Body.headlights.on.Value = true else src.Parent.Parent.Body.headlights.on.Value = false end end
This is saying that you're missing a closing parenthesis, why you may ask? You're creating a raw function to pass as the callback argument for the .KeyDown
signal, which can sometimes make it harder to take in perspective in what your code is really looking like. If we collapse the line, you'll notice the code is reading:
Instance.Event:Connect(
You simply need to close the argumental parentheses. Most people just leave the closing parenthesis at function end.
local mouse=game.Players.LocalPlayer:GetMouse() script.Parent:WaitForChild("src3") local src = script.Parent.src3.Value mouse.KeyDown:connect(function(key) if key=="h" and src.Parent.Parent.Body.headlights.on.Value == true then src.Parent.Parent.Body.headlights.on.Value = true else src.Parent.Parent.Body.headlights.on.Value = false end end)
Your code is also pretty deprecated, meaning there are parts of your code that ROBLOX doesn't support anymore. For generic KeyBinding, we now use UserInputService. The .InputBegan
signal will be what we tie a listener to:
local UserInputService = game:GetService("UserInputService") local Player = game:GetService("Players").LocalPlayer local Source = script.Parent:WaitForChild("src3").Value UserInputService.InputBegan:Connect(function(Input, GameProcessed) if (GameProcessed) then return end if (Input.KeyCode == Enum.KeyCode.H) then if (src.Parent.Parent.Body.headlights.on.Value == true) then src.Parent.Parent.Body.headlights.on.Value = true else src.Parent.Parent.Body.headlights.on.Value = false end end end)
It's because you didn't close the bracket for the function like this
local mouse=game.Players.LocalPlayer:GetMouse() local src = script.Parent:WaitForChild("src3").Value mouse.KeyDown:connect(function(key) if key == Enum.KeyCode.H and src.Parent.Parent.Body.headlights.on.Value then src.Parent.Parent.Body.headlights.on.Value = true else src.Parent.Parent.Body.headlights.on.Value = false end end) --Done