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)
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.
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
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
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)
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.-”?
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
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.