Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I name a Folder something with code in it and stuff in ""?

So i made a script to make a folder in SoundService. Its erroring with

ServerScriptService.OnJoining.Script:7: attempt to call a string value>

Im pretty sure its something simple

The script is in ServerScriptService

local Players = game:GetService("Players")
local SoundService = game:GetService("SoundService")

Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder")
	Folder.Parent = SoundService
	Folder.Name = plr.Name" Sounds"
end)

I tried searching if someone had the same problem as me, Im pretty sure there is one but just titled differently from what im looking up.

2 answers

✓ Accepted answer

you had one tiny error. You forgot to add text wrapping when mixing strings together. what I mean is the ". ." in between plr.Name and " Sounds"

here is the fixed script in case you still don't know what I mean:

local Players = game:GetService("Players")
local SoundService = game:GetService("SoundService")

Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder",SoundService) -- yes, you can set the parent in the instance function
	Folder.Name = plr.Name.."'s Sounds" -- the line that errored which I fixed

1 comment

0

Thankyou, Its always the small stuff i miss.

In line 7, you didn't add concatenation, which is ".." used to connect strings. The game thinks you are calling a method because doing

plr.Name"Sounds"

is the same as doing

plr.Name("Sounds")

Instead you should use concatenation. This is an example

local a = "Hello"
local b = "World"

print(a..b) -- prints "HelloWorld". It connects "Hello" (a) with "World" (b)

print(a.." "..b) -- this prints "Hello World". It connects "Hello" (a) and then connects a space which makes the string into "Hello " and then connects it with "World" (b) which makes the string into "Hello World"

Here is your code with the correction

local Players = game:GetService("Players")
local SoundService = game:GetService("SoundService")

Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder",SoundService)
	Folder.Name = plr.Name.." Sounds" -- Sets the folder's name to "[PlayerNameHere] Sounds", Because it connects the player's name and then connects it " Sounds" or basically "[PlayerName] Sounds"
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.