String being passed through remote event is returning as nil when printing

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

What I would like to achieve is to make a functional surface gui for a radio in a boat in my game.

  1. What is the issue?

The issue I am having with this is when I try passing a string through a remote event from a local script to a server script and print the string, it always returns as nil.

Here’s an image of the output:

  1. What solutions have you tried so far?

I have tried changing some code around and making different ways of passing the string to the server script.

Here is the code in the code in the local script along with the gui in startergui:

local part = script.PartName.Value
local ID = script.Parent.Frame.ID.Text
local enter = script.Parent.Frame.enter
local event = game.ReplicatedStorage.Events.ChangeAudioID


enter.MouseButton1Click:Connect(function(player)
	event:FireServer(player,part,ID)
end)

image

Here is the code and photo of the server part of it:

local event = game.ReplicatedStorage.Events.ChangeAudioID
local audio = script.Parent.Sound


event.OnServerEvent:Connect(function(player,part,ID)
	print("Player: "..player.Name)
	print("Part: "..part)
	print("ID: "..ID)
	
	if part == script.Parent.Name then
		audio.SoundId = "rbxassetid://"..ID
		audio:Play()
	end
end)

EDIT:
Here is the remote event in replicated Storage:
image

Thank you for anything that may help with fixing this issue.

You don’t pass in the player in FireServer, it is done so automatically, passing the player should be done if you’re using FireClient

event:FireServer(part,ID)

Though you also have some other issues, you’re immediately getting the values even before you fire the event,

local part = script.PartName.Value
local ID = script.Parent.Frame.ID.Text

Should be inside your MouseButton1Click event

1 Like

thanks for that, I’ve tried what you have said and it now works perfectly fine.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.