Expected identifier when parsing expression, got '['

I recently followed some random tutorial on YouTube to script a working Law Enforcement radio, it looks good and most people got it working but sadly I was one of the many who had one error after copying it all correctly. The error “Expected identifier when parsing expression, got ‘[’”.

The code:

local Player = game.Players.LocalPlayer
local UserInputService = game:GetService(“UserInputService”)“UserInputService”
local RadioFrame = script.Parent.RadioFrame
local ActiveChange = RadioFrame.Frame.ActiveChange
local frame1 = RadioFrame.Frame

local ChannelTextLabel = RadioFrame.ChannelTextLabel

local Channels = [“Global”]

local RadioRemoteEvent = game.ReplicatedStorage.RadioRemoteEvents
local RadioEvent = RadioRemoteEvents.RadioEvent

CurrentChannel = “Global”
Active = false

function DefineNewIncrement(Increment)
local NewIncrement = Increment
if Increment < 3 then
NewIncrement = Increment ÷ 1
elseif Increment > = 3 then
NewIncrement = 1
end
return NewIncrement
end

function ChangeActive()
if Active = false then
Active = true
ActiveChange.BackgroundColor3 = Color3.fromRGB(0,117,0)
frame1.ImageColor3 = Color3.fromRGB(0,117,0)
ActiveChange.Text = “(-) Active”
local.PlaySound
script.Parent.RadioFrame.Sound1: Play( )
script.Parent.RadioFrame.ActiveChange.Active:connect (PlaySound())
elseif Active == true then
Active = false
ActiveChange.BackgroundColor3 = Color3.fromRGB(117,0,0)
frame1.ImageColor3 = Color3.fromRGB(117,0,0)
ActiveChange.Text = “(-) Inactive”
local PlaySound
script.Parent.RadioFrame.Sound2: Play( )
script.Parent.RadioFrame.ActiveChange.Active:connect (PlaySound())
end
end

UserInputService.InputBegan:Connect(function(Key, IsTyping)
if IsTyping then return end
if Key.Keycode = Enum.KeyCode.Hyphen then
ChangeActive()
end
end)

ActiveChange.MouseButton1Click:Connect(function()
ChangeActive()
end)

Player.Chatted:Connect(function(Message)
if Active = false then return end
print(Player.Name…" - “…CurrentChannel…”: "…Message
RadioEvent:FireServer(Message,CurrentChannel)
end)

The error is at:

local Channels = [“Global”]

Sorry if I formatted this wrong, this is my first post and I am unsure on how to format code in a post like others do.

I’m not entirely sure if Channels is meant to be a string or a table, but try changing the [] to {} and see if that fixes it. If not, remove them. To clarify a bit more, the brackets [] aren’t used when defining something.

When I use {} instead of [], then the error goes down to

function DefineNewIncrement(Increment)
local NewIncrement = Increment
if Increment < 3 then
NewIncrement = Increment ÷ 1
elseif Increment > = 3 then
NewIncrement = 1
end
return NewIncrement
end

At the part where it says “NewIncrement = Increment ÷ 1”
Without any brackets or anything around “Global” the same error when replacing [] to {} occurs.

The YouTube link if required for any reason:

In the description of the video, it seems some people did come across the same error as me and were never given a straight solution to fix it.

÷ is not a valid operand/expression in Lua. If you meant to subtract, use -, or if you meant to divide it, use /.

After I swapped the division sign to a / and have no brackets around the “Global”, the error then goes down to

function DefineNewIncrement(Increment)
local NewIncrement = Increment
if Increment < 3 then
	NewIncrement = Increment / 1
elseif Increment > = 3 then
	NewIncrement = 1
end
return NewIncrement
end

At the part where it says

elseif Increment > = 3 then

The equals part being the error now.

The > and = should be combined, like so:
elseif Increment >= 3 then

After I correct what you said to correct just then, the error then falls down to

function ChangeActive()
if Active = false then
	Active = true
	ActiveChange.BackgroundColor3 = Color3.fromRGB(0,117,0)
	frame1.ImageColor3 = Color3.fromRGB(0,117,0)
	ActiveChange.Text = "(-) Active"
	local.PlaySound
	script.Parent.RadioFrame.Sound1: Play(		)
	script.Parent.RadioFrame.ActiveChange.Active:connect	(PlaySound())
elseif Active == true then
	Active = false
	ActiveChange.BackgroundColor3 = Color3.fromRGB(117,0,0)
	frame1.ImageColor3 = Color3.fromRGB(117,0,0)
	ActiveChange.Text = "(-) Inactive"
	local PlaySound
	script.Parent.RadioFrame.Sound2: Play(		)
	script.Parent.RadioFrame.ActiveChange.Active:connect (PlaySound())
end	
end

At the part

if Active = false then

The error being the equals.

Theres many missing symbols like if Active = false… Should be if Active == false

I changed many typos, check if works (surely still doesnt work xD)

Another thing: local.PlaySound ???

EDIT: Still a mess… Im gonna fix more stuff :vvv

The error then goes to

local.PlaySound

Do I know its purpose of being in the code?
Of course not :joy:

The script is a real total mess of typos, and looks like its intended to be like that… Why? Is this a joke from that youtuber? Its meant for you to fix it or something?

Try this one now… I guess I fixed all typos already (I guess)

local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local RadioFrame = script.Parent.RadioFrame
local ActiveChange = RadioFrame.Frame.ActiveChange
local frame1 = RadioFrame.Frame

local ChannelTextLabel = RadioFrame.ChannelTextLabel

local Channels = {"Global"}

local RadioRemoteEvent = game.ReplicatedStorage.RadioRemoteEvents
local RadioEvent = RadioRemoteEvents.RadioEvent

CurrentChannel = "Global"
Active = false

function DefineNewIncrement(Increment)
	local NewIncrement = Increment
	if Increment < 3 then
		NewIncrement = Increment / 1
	elseif Increment >= 3 then
		NewIncrement = 1
	end
	return NewIncrement
end

function ChangeActive()
	if Active == false then
		Active = true
		ActiveChange.BackgroundColor3 = Color3.fromRGB(0,117,0)
		frame1.ImageColor3 = Color3.fromRGB(0,117,0)
		ActiveChange.Text = "(-) Active"
		local PlaySound
		script.Parent.RadioFrame.Sound1: Play( )
		script.Parent.RadioFrame.ActiveChange.Active:Connect(PlaySound())
	elseif Active == true then
		Active = false
		ActiveChange.BackgroundColor3 = Color3.fromRGB(117,0,0)
		frame1.ImageColor3 = Color3.fromRGB(117,0,0)
		ActiveChange.Text = "(-) Inactive"
		local PlaySound
		script.Parent.RadioFrame.Sound2: Play( )
		script.Parent.RadioFrame.ActiveChange.Active:Connect(PlaySound())
	end
end

UserInputService.InputBegan:Connect(function(Key, IsTyping)
	if IsTyping then return end
	if Key.Keycode == Enum.KeyCode.Hyphen then
		ChangeActive()
	end
end)

ActiveChange.MouseButton1Click:Connect(function()
	ChangeActive()
end)

Player.Chatted:Connect(function(Message)
	if Active == false then return end
	print(Player.Name.. " - " .. CurrentChannel .. ": " ..Message)
		RadioEvent:FireServer(Message,CurrentChannel)
end)

EDIT: Liee… Still more typos…

Hey, it works! The only error being the keycode which is my fault. I don’t know what I must write for hyphen when writing “Enum.KeyCode.Hyphen” being the way I wrote it. Should it be “Enum.KeyCode.-”?

No, but you can look a list if you search Enum.KeyCode on the developer hub.
KeyCode | Documentation - Roblox Creator Hub

Nope, it doesnt work, Now this should work!

local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local RadioFrame = script.Parent.RadioFrame
local ActiveChange = RadioFrame.Frame.ActiveChange
local frame1 = RadioFrame.Frame

local ChannelTextLabel = RadioFrame.ChannelTextLabel

local Channels = {"Global"}

local RadioRemoteEvent = game.ReplicatedStorage.RadioRemoteEvents
local RadioEvent = RadioRemoteEvent.RadioEvent

CurrentChannel = "Global"
Active = false

function DefineNewIncrement(Increment)
	local NewIncrement = Increment
	if Increment < 3 then
		NewIncrement = Increment / 1
	elseif Increment >= 3 then
		NewIncrement = 1
	end
	return NewIncrement
end

function ChangeActive()
	if Active == false then
		Active = true
		ActiveChange.BackgroundColor3 = Color3.fromRGB(0,117,0)
		frame1.ImageColor3 = Color3.fromRGB(0,117,0)
		ActiveChange.Text = "(-) Active"
		local PlaySound
		script.Parent.RadioFrame.Sound1: Play( )
		script.Parent.RadioFrame.ActiveChange.Active:Connect(PlaySound())
	elseif Active == true then
		Active = false
		ActiveChange.BackgroundColor3 = Color3.fromRGB(117,0,0)
		frame1.ImageColor3 = Color3.fromRGB(117,0,0)
		ActiveChange.Text = "(-) Inactive"
		local PlaySound
		script.Parent.RadioFrame.Sound2: Play( )
		script.Parent.RadioFrame.ActiveChange.Active:Connect(PlaySound())
	end
end

UserInputService.InputBegan:Connect(function(Key, IsTyping)
	if IsTyping then return end
	if Key.Keycode == Enum.KeyCode.Minus then
		ChangeActive()
	end
end)

ActiveChange.MouseButton1Click:Connect(function()
	ChangeActive()
end)

Player.Chatted:Connect(function(Message)
	if Active == false then return end
	print(Player.Name.. " - " .. CurrentChannel .. ": " ..Message)
		RadioEvent:FireServer(Message,CurrentChannel)
end)

EDIT: True that Hypen doesnt exist. :v
EDIT2: Ok, Hyphen changed for Minus thank @JarodOfOrbiter
Check that, if works now.
Wow… Why so many typos? is somekind of exersice? or a joke? xDD

Good-looking is an example of a hypenated word.
Hyphen is the same as minus on a keyboard. It’s Enum.KeyCode.Minus

1 Like

“Keycode is not a valid member of InputObject “InputObject” - Client - RadioClient:49”

All works well except the keybind.

Would be helpful if you show me the hierarchy. Im creating all remotes, frames, labels, etc, just by reading the script… just to test it to see if works.

Send a pic of the hierarchy. Or the file, pls :3


Screen Shot 2021-01-14 at 12.51.10 pm

1 Like

ohhh Okie. Change

Key.Keycode for Key.UserInputType

:v

Keybind doesn’t work still but no errors appear for the keybind.
Also

ActiveChange is not a valid member of ImageLabel “Players.iiQuackii.PlayerGui.RadioGui.RadioFrame” - Client - RadioClient:35

When enabled by clicking the button ^^
And

ActiveChange is not a valid member of ImageLabel “Players.iiQuackii.PlayerGui.RadioGui.RadioFrame” - Client - RadioClient:43

When disabled by clicking the button ^^