How would i name a value object through a textbox

Hello, i am not sure how to name a object through a textbox. I tried an remoteevent but it seems that the object name is still blank. Here are the scripts

ServerScript:

local replicatedStorage = game:GetService("ReplicatedStorage")

local remotes = replicatedStorage.Remotes

game.Players.PlayerAdded:Connect(function(player)
	remotes.CreateSong.OnServerEvent:Connect(function()
		local CMUI = player.PlayerGui.Misc.CreateMusic
		local newSongValue = Instance.new("BoolValue", player.Bools.Songs)
		newSongValue.Name = CMUI.SongName.Value
	end)
end)

LocalScript:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.SongName.Value = script.Parent.Parent.SongTTL.Text
	game.ReplicatedStorage.Remotes.CreateSong:FireServer(player)
end)

In the local script, don’t send the player with the remote event as roblox sends it automatically.

Sure thanks, but it still doesn’t seem to set the name of the object

1 Like

“but it seems that the object name is still blank.”

– Try to do it from the client instead of the server

I’ll try, but I wanted to do it through the server because i wanted to save the values inside the player

Remove the playeradded, OnServerEvent’s first parameter always is the player who fired the event, so put player in its brackets

You change the value on the client and try to get it on the server, the value isn’t replicated so it wont notice the change, you’d have to pass in the songname through the FireServer, and remove player from the FireServer as well since it’s done automatically

2 Likes

Pass through as in something like this?

	game.ReplicatedStorage.Remotes.CreateSong:FireServer(songName)
1 Like

That’s correct, where songName is the name of the song in question, Make sure to include this as a parameter on the OnServerEvent as well so you cna use it

Now, i put the mention of songName but it still didn’t work

ServerScript

	remotes.CreateSong.OnServerEvent:Connect(function(player, songName)
		local CMUI = player.PlayerGui.Misc.CreateMusic
		local newSongValue = Instance.new("BoolValue", player.Bools.Songs)
	newSongValue.Name = CMUI.SongName.Value
	end)

LocalScript

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local songName = script.Parent.Parent.SongName.Value
	script.Parent.Parent.SongName.Value = script.Parent.Parent.SongTTL.Text
	game.ReplicatedStorage.Remotes.CreateSong:FireServer(songName)
end)

A few things

You store the value into a variable too early because next line you change the value, you don’t really need a variable in this case, just pass in the value of SongName into the FireServer directly

Your OnServerEvent doesn’t use songName, it still tries to get it directly, which can’t work due to replication, use songName where you try to get the value directly

Something like this?

	remotes.CreateSong.OnServerEvent:Connect(function(player, songName)
		local CMUI = player.PlayerGui.Misc.CreateMusic
	local newSongValue = Instance.new("BoolValue", player.Bools.Songs)
	local songName = player.Bools.SongName
	newSongValue.Name = songName.Value
	end)

I did the playeradded to have a player variable too

(which i removed)

That’s not what I’m saying, you have the songName parameter on your OnServerEvent, you use that to change the name of newSongValue

I did this and it gave me a error:

	remotes.CreateSong.OnServerEvent:Connect(function(player, songName)
		local CMUI = player.PlayerGui.Misc.CreateMusic
	local newSongValue = Instance.new("BoolValue", player.Bools.Songs)
	newSongValue.Name = songName.Value
	end)

Error: Unable to assign property Name. string expected, got nil - Server - RemoteHandler:10

You don’t need to do .Value, in the FireServer, pass in the value of songName

1 Like

You don’t need to catch the remote event inside playeradded. Player is automatically passed in when the remote event is fired. That is your problem, you are catching it multiple times from every player.

Wait im sorry i understood it wrong

Yes but the thing is, it doesn’t know the value of SongName so it’ll nil

remotes.CreateSong.OnServerEvent:Connect(function(player, songName)
	local newSongValue = Instance.new("BoolValue", player.Bools.Songs)
	newSongValue.Name = songName
end)
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local songName = script.Parent.Parent.SongName
	songName.Value = script.Parent.Parent.SongTTL.Text
	game.ReplicatedStorage.Remotes.CreateSong:FireServer(songName.Value)
end)
1 Like

Thanks a lot. It works now, i just forgot to add the .Value

1 Like