Server script does not receive input in TextBox from client

Hello. I’m trying to make a system where players can enter a Sound ID in the TextBox, click a button, and add it to a folder on the server. While writing the scripts, I ran into a problem: the server script doesn’t get the text from the TextBox and just outputs nothing or nil (depending on how you change the script). In addition, the script gives an error when trying to change the name of the sound (see below the code for all errors).

Here’s how I wrote this system:

-- Local script inside of a GUI.
local Gui = script.Parent
local DJui = Gui.Frame.DJ

DJui.ID.Add.MouseButton1Click:Connect(function()
	if DJui.ID.Text == "" then
		DJui.Output.Text = "ID can't be empty."
		DJui.Output.TextColor3 = Color3.fromRGB(255, 38, 42)
	end
	local MarketplaceService = game:GetService'MarketplaceService'
	local Success, Response = pcall(MarketplaceService.GetProductInfo, MarketplaceService, DJui.ID.Text)

	if Success then
		if Response.AssetTypeId == Enum.AssetType.Audio.Value then
			if DJui.ID.Text ~= "" and DJui.Output.TextColor3 ~= Color3.fromRGB(255, 38, 42) then
				local event = game.ReplicatedStorage.DJSongToServer
				print(DJui.ID.Text)
				event:FireServer(DJui.ID.Text)
			end
		end
	end
end)

-- Server script inside of a ServerScriptService
local event = game.ReplicatedStorage.DJSongToServer
local folderChildren = game.Workspace.Ambience.CafeRadio:GetChildren()

local DJGamepass = 884995252
local DJ = {}

event.OnServerEvent:Connect(function(player, ID)
	if table.find(DJ, player.Name) or game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, DJGamepass) then
		ID = player.PlayerGui.MusicGui.Frame.DJ.ID.Text -- An attempt to make it receive the ID from the player's GUI.
		print(ID) -- Still doesn't receive anything.
		local Sound = Instance.new("Sound")
		Sound.SoundId = "rbxassetid://"..ID
			Sound.Parent = game.Workspace.Ambience.CafeRadio
			Sound.Volume = 0.5
		Sound.Name = game:GetService("MarketplaceService"):GetProductInfo(ID,Enum.InfoType.Asset).Name 
       -- Line 15
	end 
end)

Errors that occurred during the test:

  11:42:27.973  Unable to cast string to int64  -  Server - SongToServer:15
  11:42:27.973  Stack Begin  -  Studio
  11:42:27.973  Script 'ServerScriptService.SongToServer', Line 15  -  Studio - SongToServer:15
  11:42:27.973  Stack End  -  Studio

  11:42:28.116   ▶ Failed to load sound rbxassetid://: HTTP 404 (Not Found) (x2)  -  Studio
  -- Errors at line 12

Do you have any ideas on how to fix both of these errors? I would be very thankful!

You have to pass a number and you’re passing the value of a Text property, which is a string. You can convert the string into a number. Although you should also make sure the result isn’t nil or the script will error again if the string is empty or contains letters

DJui.ID.Add.MouseButton1Click:Connect(function()
	if DJui.ID.Text == "" then
		DJui.Output.Text = "ID can't be empty."
		DJui.Output.TextColor3 = Color3.fromRGB(255, 38, 42)
	end
    local id = tonumber(DJui.ID.Text);
    if id == nil then return end; -- it's an invalid value
	local MarketplaceService = game:GetService'MarketplaceService'
	local Success, Response = pcall(MarketplaceService.GetProductInfo, MarketplaceService, id)

	if Success then
		if Response.AssetTypeId == Enum.AssetType.Audio.Value then
			if DJui.ID.Text ~= "" and DJui.Output.TextColor3 ~= Color3.fromRGB(255, 38, 42) then
				local event = game.ReplicatedStorage.DJSongToServer
				print(DJui.ID.Text)
				event:FireServer(id)
			end
		end
	end
end)

The server continues to receive nothing, both errors also remained. It successfully gets the value in the local script, but when transferring this all through RemoteEvent the argument is just passed empty.

Oops sorry, I just noticed.

ID = player.PlayerGui.MusicGui.Frame.DJ.ID.Text

This can’t work cause the server cannot see text written on the client. Remove this line and the server should get the correct ID from the remote event

1 Like

Everything worked, thank you very much!

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