You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m experimenting with plugins, and I want to make one that makes a leaderstat, and to do that I need to pass variables (strings and numbers) from the plugin’s GUI to the script that it generates.
What is the issue? Include screenshots / videos if possible!
I have no idea how to pass the variables to it, I’ve tried one solution, by making a stringValue instance and settings its parent to the script, altho that makes a lot of mess and I don’t want that.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have seen one person do this with tables, I don’t know how id implement that into my project.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Plugin script:
-- local ServerScriptService = game:GetService("ServerScriptService")
local TextChatService = game:GetService("TextChatService")
local toolbar = plugin:CreateToolbar("Easy Leaderstats")
local button = toolbar:CreateButton("Make Leaderstat","Opens the Easy Leaderstat menu.","")
local gui = script:WaitForChild("GUI",10)
button.Click:Connect(function()
gui.CanvasGroup.Position = UDim2.new(0.36, 0,0.036, 0)
gui.CanvasGroup.Draggable = true
if gui.Parent == script then
gui.Parent = game:WaitForChild("CoreGui")
elseif gui.Parent == game:WaitForChild("CoreGui") then
gui.Parent = script
end
end)
gui.CanvasGroup.CreateValue.MouseButton1Click:Connect(function()
local LeaderstatsFolder, leaderstatsScript
if not ServerScriptService:FindFirstChild("EasyLeaderstats") then
LeaderstatsFolder = Instance.new("Folder")
LeaderstatsFolder.Name = "EasyLeaderstats"
LeaderstatsFolder.Parent = ServerScriptService
else
LeaderstatsFolder = ServerScriptService:WaitForChild("EasyLeaderstats")
end
repeat wait() until LeaderstatsFolder ~= nil
if not LeaderstatsFolder:FindFirstChild("LeaderstatsManager") then
leaderstatsScript = Instance.new("Script")
leaderstatsScript.Name = "LeaderstatsManager"
leaderstatsScript.Parent = LeaderstatsFolder
else
leaderstatsScript = leaderstatsScript:WaitForChild("LeaderstatsManager")
end
local textbox1 = gui.CanvasGroup:WaitForChild("ValueName")
local textbox2 = gui.CanvasGroup:WaitForChild("Value")
local valueName = textbox1.Text
local value = textbox2.Text
local strVl1 = Instance.new("StringValue")
local strVl2 = Instance.new("StringValue")
strVl1.Parent = leaderstatsScript
strVl2.Parent = leaderstatsScript
strVl1.Value = valueName
strVl2.Value = value
leaderstatsScript.Source = [[
-- //Please help me
print("valueName: "..script.strVl1.Value.."|| Value: "..script.strVl2.Value)
]]
task.wait()
strVl1:Destroy()
strVl2:Destroy()
textbox1.Text = ""
textbox2.Text = ""
end)
How I want the script to generate:
-- //Please help me
print("valueName: Name || Value: 200")
How it generates:
-- //Please help me
print("valueName: "..script.strVl1.Value.."|| Value: "..script.strVl2.Value)
IIRC, using the [[ ]] string literal syntax means exactly that, a literal. I don’t think there is any support for escaping out of it or any kind of tokens within it the literal span. I’m pretty sure you have to do things the hard way, with concatination and escaped characters, e.g.:
leaderstats.Script.Source = "-- //Please help me\nprint(\"valueName: "..script.strVl1.Value.."|| Value: " ..script.strVl2.Value.."\")"
or you can retain the [[ ]] syntax for the literal substrings, so that you don’t need to escape as many characters with backslash, but you’ll still need to add back the line breaks either inside the [[ ]] or between them with a “\n” or equivalent string.char(10):
Thanks!, But how would i make the values stack? I’ve been scripting for over an year now but never really got deep into string related stuff, I have the script working and it looks a bit like this when its generated:
--\\Script made by EasyLeaderstats
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local value = Instance.new("NumberValue")
value.Name = "Cash"
value.Value = 200
value.Parent = leaderstats
end)
I’ve also modified the plugin script.
local ServerScriptService = game:GetService("ServerScriptService")
local toolbar = plugin:CreateToolbar("Easy Leaderstats")
local button = toolbar:CreateButton("Make Leaderstat","Opens the Easy Leaderstat menu.","")
local gui = script:WaitForChild("GUI",10)
button.Click:Connect(function()
gui.CanvasGroup.Position = UDim2.new(0.36, 0,0.036, 0)
gui.CanvasGroup.Draggable = true
if gui.Parent == script then
gui.Parent = game:WaitForChild("CoreGui")
elseif gui.Parent == game:WaitForChild("CoreGui") then
gui.Parent = script
end
end)
gui.CanvasGroup.CreateValue.MouseButton1Click:Connect(function()
local LeaderstatsFolder, leaderstatsScript
if not ServerScriptService:FindFirstChild("EasyLeaderstats") then
LeaderstatsFolder = Instance.new("Folder")
LeaderstatsFolder.Name = "EasyLeaderstats"
LeaderstatsFolder.Parent = ServerScriptService
else
LeaderstatsFolder = ServerScriptService:FindFirstChild("EasyLeaderstats")
end
repeat wait() until LeaderstatsFolder ~= nil
if not LeaderstatsFolder:FindFirstChild("LeaderstatsManager") then
leaderstatsScript = Instance.new("Script")
leaderstatsScript.Name = "LeaderstatsManager"
leaderstatsScript.Parent = LeaderstatsFolder
else
leaderstatsScript = leaderstatsScript:FindFirstChild("LeaderstatsManager")
end
local textbox1 = gui.CanvasGroup:WaitForChild("ValueName")
local textbox2 = gui.CanvasGroup:WaitForChild("Value")
local valueName = textbox1.Text
local value = textbox2.Text
leaderstatsScript.Source = [[--\\Script made by EasyLeaderstats]]
.."\n"..[[local Players = game:GetService("Players")]]
.."\n"..[[Players.PlayerAdded:Connect(function(player)]]
.."\n"..[[local leaderstats = Instance.new("Folder")]]
.."\n"..[[leaderstats.Name = "leaderstats"]]
.."\n"..[[leaderstats.Parent = player]]
.."\n"..[[local value = Instance.new("NumberValue")]]
.."\n"..[[value.Name = "]]..valueName..[["]]
.."\n"..[[value.Value = ]]..value
.."\n"..[[value.Parent = leaderstats]]
.."\n"..[[end)]]
task.wait()
textbox1.Text = ""
textbox2.Text = ""
end)
Im just a bit confused on how i’d make the values stack?, because if I try to run the plugin again it gives me this error: PluginDebugService.user_Plugin.rbxmx.Plugin.Script:45: attempt to index nil with ‘FindFirstChild’