Remote Event and Function Issue

On my client-side, I have:

PanicButton.MouseButton1Click:Connect(function()
	local Message = "**PANIC BUTTON PRESSED**"
	local Type = "panic"
	
	RadioEvent:FireServer(Message,CurrentChannel,Type,game.Players.LocalPlayer.Name,game.Players.LocalPlayer.UserId)
end)

Player.Chatted:Connect(function(Message)
	if Active == false then return end
	local Type = "radio"
	
	RadioEvent:FireServer(Message,CurrentChannel,Type,game.Players.LocalPlayer.Name,game.Players.LocalPlayer.UserId)
end)

This is printing:

  • **PANIC BUTTON PRESSED**
  • Global
  • radio
  • Aka_Ethan110
  • 476512066

On my server-side, I have:

RadioEvent.OnServerEvent:Connect(function(Message,CurrentChannel,Type,Player,Player2)
	print(Message)
	print(CurrentChannel)
	print(Type)
	print(Player)
	print(Player2)
end)

This is printing:

  • Aka_Ethan110
  • **PANIC BUTTON PRESSED**
  • Global
  • radio
  • Aka_Ethan110

There is more code than this, however I think this is the code which is relevant to the issue.

1 Like

OnServerEvent has a default first parameter of player. Message was equal to it. Use the core below

RadioEvent.OnServerEvent:Connect(function(playerWhoFired, Message,CurrentChannel,Type,Player,Player2)
	print(Message)
	print(CurrentChannel)
	print(Type)
	print(Player)
	print(Player2)
end)

I wouldn’t add the player1 and 2 parameters there, because the player is passed automatically. So just reference playerWhoFired.Name and .UserId

5 Likes

Yep to add on the documentation Roblox has , really helps as well especially this article on remote events:

Note that the connected function (lines 6-12) will receive the Player who fired the event as its first parameter ( player ), along with any additional parameters passed from the FireServer() call.

4 Likes

Thanks. I now have another issue. Here is my code:

function DisplayMessage(FrameToOutput,Message)
	FrameToOutput.LineFour.TextLabel.Text = FrameToOutput.LineThree.TextLabel.Text 
	FrameToOutput.LineThree.TextLabel.Text = FrameToOutput.LineTwo.TextLabel.Text 
	FrameToOutput.LineTwo.TextLabel.Text = FrameToOutput.LineOne.TextLabel.Text 
	FrameToOutput.LineOne.TextLabel.Text = Message
end

RadioEvent.OnServerEvent:Connect(function(Player,Message,CurrentChannel,Type)
   ConfigMessage(Player.Name,Message,CurrentChannel,Type)
end)

function ConfigMessage(Player,Message,Channel,Type)
	print(Message)
	print(Channel)
	print(Type)
	print(Player)
	
	local RadioGui = script.Parent
	local FrameToOutput = script.Parent:FindFirstChild(Channel)
	local ConfiguredMessage = Player..": "..Message
	DisplayMessage(FrameToOutput,ConfiguredMessage)
end

RadioEvent.OnServerEvent:Connect(function(Player,Message,CurrentChannel,Type)
	ConfigMessage(Message,CurrentChannel,Type,Player)
	
	if Type == "panic" then
		game.Workspace.PanicButtonSound:Play()
	else
		game.Workspace.RadioSound:Play()
	end
end)

It prints everything as it should, however:

  • The panic button sound does not play
  • I get this error: attempt to index nil with 'LineFour'
1 Like

I need to know where the error is. If you could also structure this so I know where these scripts are that’d be appreciated.

2 Likes

All the code is in one script on the server-side. It is erroring on this line: FrameToOutput.LineFour.TextLabel.Text = FrameToOutput.LineThree.TextLabel.Text

1 Like

That means you made an issue in referencing FrameToOutput. Verify that Channel is the right string and that it matches the item you are looking for.

2 Likes

Okay, what about the issue with the sound not playing?

1 Like

Verify that you are sending the proper Type. It would be useful if I saw the client.

2 Likes

Local Script:

-- Variables

local Player = game.Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")

local RadioFrame = script.Parent

local ActiveChange = RadioFrame.ActiveInactive.ActiveChange

local ChannelChange = RadioFrame.ChannelChangeText.ChannelChange

local ChannelTextLabel = RadioFrame.CurrentChannel.ChannelTextLabel

local PanicButton = RadioFrame.PanicButton.PanicButton

-- Channel List

local Channels = {"Global","Police","Fire"}

-- Remote Events

local RadioRemoteEvents = game.ReplicatedStorage.RadioRemoteEvents

local RadioEvent = RadioRemoteEvents.RadioEvent

-- Program Global Variables

CurrentChannel = "Global"

Active = false

-- Define New Increment

function DefineNewIncrement(Increment)

local NewIncrement = Increment

if Increment < 3 then

NewIncrement = Increment + 1

elseif Increment >= 3 then

NewIncrement = 1

end

return NewIncrement

end

-- Change Channnel

function ChangeChannel()

local Increment = table.find(Channels,CurrentChannel)

local NewIncrement = DefineNewIncrement(Increment)

CurrentChannel = Channels[NewIncrement]

ChannelTextLabel.Text = "C: "..CurrentChannel

RadioFrame:FindFirstChild(Channels[Increment]).Visible = false

RadioFrame:FindFirstChild(CurrentChannel).Visible = true

end

-- Change Active

local RadioAnimationTrack

local RadioAnimation = script.RadioAnimation

local player = game.Players.LocalPlayer

local char = player.Character

local hum = char:WaitForChild("Humanoid")

function ChangeActive()

if Active == false then

RadioAnimationTrack = hum:LoadAnimation(RadioAnimation)

Active = true

RadioAnimationTrack:Play()

ActiveChange.Text = "(T) Active"

ActiveChange.Parent.ImageColor3 = Color3.fromRGB(255,0,0)

elseif Active == true then

Active = false

RadioAnimationTrack:Stop()

ActiveChange.Text = "(T) Inactive"

ActiveChange.Parent.ImageColor3 = Color3.fromRGB(11,101,107)

end

end

-- User Input Service

UserInputService.InputBegan:Connect(function(Key, IsTyping)

if IsTyping then return end

if Key.KeyCode == Enum.KeyCode.Y then

ChangeChannel()

elseif Key.KeyCode == Enum.KeyCode.T then

ChangeActive()

end

end)

-- Button Function

ChannelChange.MouseButton1Click:Connect(function()

ChangeChannel()

end)

-- Button Function

ActiveChange.MouseButton1Click:Connect(function()

ChangeActive()

end)

PanicButton.MouseButton1Click:Connect(function()

local Message = "**PANIC BUTTON PRESSED**"

local Type = "panic"

RadioEvent:FireServer(Message,CurrentChannel,Type,game.Players.LocalPlayer.Name,game.Players.LocalPlayer.UserId)

end)

-- Player Chatter

Player.Chatted:Connect(function(Message)

if Active == false then return end

local Type = "radio"

RadioEvent:FireServer(Message,CurrentChannel,Type,game.Players.LocalPlayer.Name,game.Players.LocalPlayer.UserId)

end)

Server Script:

local hookURL = ""
local hookURL2 = ""
local httpService = game:GetService("HttpService")

-- Remote Events
local RadioRemoteEvents = game.ReplicatedStorage.RadioRemoteEvents
local RadioEvent = RadioRemoteEvents.RadioEvent
local PanicEvent = RadioRemoteEvents.PanicButton

-- Display Message
function DisplayMessage(FrameToOutput,Message)
	FrameToOutput.LineFour.TextLabel.Text = FrameToOutput.LineThree.TextLabel.Text 
	FrameToOutput.LineThree.TextLabel.Text = FrameToOutput.LineTwo.TextLabel.Text 
	FrameToOutput.LineTwo.TextLabel.Text = FrameToOutput.LineOne.TextLabel.Text 
	FrameToOutput.LineOne.TextLabel.Text = Message
end

-- Configure Message
function ConfigMessage(Player,Message,Channel,Type)
	print(Message)
	print(Channel)
	print(Type)
	print(Player)
	
	local RadioGui = script.Parent
	local FrameToOutput = script.Parent:FindFirstChild(Channel)
	local ConfiguredMessage = Player..": "..Message
	DisplayMessage(FrameToOutput,ConfiguredMessage)
end

-- Radio Event / On-Server-Event
RadioEvent.OnServerEvent:Connect(function(Player,Message,CurrentChannel,Type)
	ConfigMessage(Message,CurrentChannel,Type,Player)
	
	if Type == "panic" then
		game.Workspace.PanicButtonSound:Play()
	else
		game.Workspace.RadioSound:Play()
	end
end)

RadioEvent.OnServerEvent:Connect(function(Player,Message,CurrentChannel,Type)
	if Type == "panic" then
		local data = {
			["embeds"] = {
				{
					["title"] = "Panic Button",
					["description"] = "[" .. Player.Name .. "](http://www.roblox.com/users/" .. tostring(Player.UserId) .. "/profile) pressed their panic button!",
					["color"] = 7506394
				}
			}
		}

		local enData = httpService:JSONEncode(data)
		httpService:PostAsync(hookURL,enData)

		ConfigMessage(Player.Name,Message,CurrentChannel,Type)
	else
		local data2 = {
			["embeds"] = {
				{
					["title"] = "Radio Transmission",
					["description"] = "[" .. Player.Name .. "](http://www.roblox.com/users/" .. tostring(Player.UserId) .. "/profile) said `".. Message .. "` on the radio!",
					["color"] = 7506394
				}
			}
		}

		local enData2 = httpService:JSONEncode(data2)
		httpService:PostAsync(hookURL2,enData2)

		ConfigMessage(Player.Name,Message,CurrentChannel,Type)
	end
end)
1 Like

It looks like an issue with the actual sound. Verify it was not removed and that the volume is correct.

2 Likes

The sound has not been taken down and the volume is at its highest.

1 Like

Is your game volume up and is there an error at all with the sound?

2 Likes

No error and my volume is up all the way.

1 Like

Have you tried debugging using print statements in your code to see if the code unexpectedly stops at a certain line? If not, I suggest doing so to make sure that the code is running as expected.

2 Likes

Yeah, it says the sound was played.

1 Like