How do you clone scripts into Tools on Roblox? - lua

So I have tried to code a script which will clone a script (Clicks) into every item in the folder (Tools), in ServerStorage. This doesn't work however and I need some help. Can anyone please help me out?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
local tools = ServerStorage:FindFirstChild("Tools") --Tools is a folder in ServerStorage
local scripts = ServerStorage:FindFirstChild("Scripts") --Scripts is a folder in ServerStorage
remotes.ToolActivated.OnServerEvent:Connect(function(player: player) --Dw about this its for my game
print(player.name)
end)
for _, tool in ipairs(tools:GetChildren()) do --Main part of where I tried to clone the script (Clicks)
local script = script.Click:Clone()
script.Parent = tool
end

Try validating that there is a Click script within the script that is being executed.
local clickScript = script:WaitForChild("Click")
for _, tool in pairs(tools:GetChildren()) do
if typeof(clickScript) ~= 'Instance' then
break
end
local clone = select(2, pcall(game.Clone, clickScript))
if typeof(clone) == 'Instance' then
clone.Parent = tool
end
end

Related

How Set Neovim startup directory to Desktop in windows?

I'm using Astro vim distro with neovide. every time I launch neovide / neovim-qt it launches in the directory it's installed on!
OS: windows 10
[Astrovim starting location][1]
[using windows shortcut properties to set start in location][2]
[1]: https://i.stack.imgur.com/ZvXfp.png
[2]: https://i.stack.imgur.com/IEl4N.png
is there a way to set startup location in options.lua ?
Try following code in your configuration file, it make use of vim\neovim autocommands feature:
local os = require("os")
local path_to_desktop = os.getenv("USERPROFILE") .. "\\Desktop"
local vim_enter_group = vim.api.nvim_create_augroup("vim_enter_group", { clear = true })
vim.api.nvim_create_autocmd(
{"VimEnter"},
{ pattern = "*", command = "cd " .. path_to_desktop, group = vim_enter_group }
)
nvim_create_autocmd and nvim_create_group are described in neovim docs. Use :h nvim_create_autocmdto find out more.

Migrate active storage from local disk service to gcs cloud

I'm trying to migrate my local Active Storage files to Google Cloud Storage. I tried to just copy the files of /storage/* to my GCS Bucket - but it seems that this does not work.
I get 404 not found errors cause it is searching for files like:
[bucket]/variants/ptGtmNWuTE...
My local storage directory has a totally different folder structure with folders like:
/storage/1R/3o/NWuT....
My method to retrieve the image is as followed:
variant = attachment.variant(resize: '100x100').processed
url_for(variant)
What am i missing here?
As it turns out - DiskService aka. local storage uses a different folder structure than the cloud services. Thats really weird.
DiskService uses as folders part of the first chars of the key.
Cloud services just use the key and put all variants in a separate folder.
Created a rake task to copy files over to cloud services. Run it with rails active_storage:migrate_local_to_cloud storage_config=google for example.
namespace :active_storage do
desc "Migrates active storage local files to cloud"
task migrate_local_to_cloud: :environment do
raise 'Missing storage_config param' if !ENV.has_key?('storage_config')
require 'yaml'
require 'erb'
require 'google/cloud/storage'
config_file = Pathname.new(Rails.root.join('config/storage.yml'))
configs = YAML.load(ERB.new(config_file.read).result) || {}
config = configs[ENV['storage_config']]
client = Google::Cloud.storage(config['project'], config['credentials'])
bucket = client.bucket(config.fetch('bucket'))
ActiveStorage::Blob.find_each do |blob|
key = blob.key
folder = [key[0..1], key[2..3]].join('/')
file_path = Rails.root.join('storage', folder.to_s, key)
file = File.open(file_path, 'rb')
md5 = Digest::MD5.base64digest(file.read)
bucket.create_file(file, key, content_type: blob.content_type, md5: md5)
file.close
puts key
end
end
end

Lua resty_dogstatsd only publishes first instance

I have a metric client that looks something like:
package.path = package.path .. ';../?.lua'
local metrics = {}
local resty_dogstatsd = require('resty_dogstatsd')
local logger = require('module.utils.logger')
local _statsd = resty_dogstatsd.new({
statsd = {
host = config.dataDog.host,
port = config.dataDog.port,
namespace = config.dataDog.namespace
},
tags = config.dataDog.tags
})
function metrics.incMetric1 ()
logger.debug('Updating metric metric1');
_statsd:increment(metric1 1, 1)
end
return metrics;
Then in my application I import it and use it
local metrics = require('module.metrics')
-- somewhere, some condition
metrics.incMetric1()
This publishes the log Updating metric metric1 in datadog and I can see it. But this will only publish the first instance. Until I restart service nginx restart, I will not get any more increments.
Update
So I have a start.lua in /etc/nginx/conf.d/start.lua that is:
package.path = package.path .. ';/path/to/my/app/?.lua'
local app = require('app.init');
app.start()
And the nginx config is
rewrite_by_lua_file /etc/nginx/conf.d/start.lua;
If I were to copy/paste the metric code into start.lua, then the metric is updated every time. Why is this?!
Update
I noticed this in the error logs:
2018/05/23 10:02:07 [error] 24483#0: *6 attempt to send data on a closed socket: u:some-hex, c:some-hex, client: 123.12.0.123, server: *.my-url.com, request: "GET / HTTP/1.1", host: "my.my-url.com"
This happens on the 2nd request to the nginx; the first time after restart, this is all fine ...
Update 2
This happens only if I have a metrics file and require it in my other. So if I instantiate the resty_dogstatsd client inside the main lua file, then everything is fine ...

SAPI is nil on cgilua.lua:93

I'm trying to install and configure cgilua on my server. I've installed Apache and lua (5.2.1.4) via apt-get and cgilua (5.2.1-1) via luarocks. on Apache, I've added the lua_mod using a2enmod. I've created a lua.conf file to associate lua-script to lua and lp files.
To test if everything was ok , I used this code:
#!/usr/bin/env lua
cgilua = require "cgilua"
cgilua.htmlheader()
if cgilua.QUERY.language == 'english' then
greeting = 'Hello World!'
elseif cgilua.QUERY.language == 'portuguese' then
greeting = 'Olá Mundo!'
else
greeting = '[unknown language]'
end
cgilua.put('<html>')
cgilua.put('<head>')
cgilua.put(' <title>'..greeting..'</title>')
cgilua.put('</head>')
cgilua.put('<body>')
cgilua.put(' <strong>'..greeting..'</strong>')
cgilua.put('</body>')
cgilua.put('</html>')
And I keep getting this error:
[lua:error] [pid 14909] AH02613: Error loading
/var/www/html/lua/index.lua: /usr/local/share/lua/5.2/cgilua.lua:93:
attempt to index upvalue 'SAPI' (a nil value)
Can somebody shed some light on this issue?

How to read a data file at a package path on Lua 5.1

How to read a data file at a package path on Lua 5.1?
What I'm looking for is something like a io.read but at the package directory instead of the working directory (arg[0]), and without using hardcoded absolute paths. That would be something like dofile does, but without running the code, only reading it as a string.
Example:
I have a test folder, the current working directory of the test.lua script.
There's a package luapackage in another folder, somewhere specified at the LUA_PATHenviroment variable.
luapackage can:
require("luapackage.other_module");
dofile("other_module.lua").
But luapackage can't do:
io.read("data.txt")
io.read("luapackage/data.txt")
Sample structure:
+-test/
|
+-test.lua
+-luamodule/
|
+-data.txt
|
+-luamodule.lua
|
+-other_module.lua
For this example, test.lua only requires luamodule:
-- test.lua
local luamodule = require("luamodule")
And luamodule needs to read its modules and data files:
-- luamodule.lua
local other_module= dofile("other_module.lua") -- works
-- local other_module= require("luamodule.other_module") -- also works
local data = io.open("data.txt") -- fails
-- local data = io.open("luamodule/data.txt") -- also fails
It doesn't work because it searches for the file at the working directory (test) and not the package directory.
If I place a copy of the package at running script's folder, io.read(luapackage/data.txt) is possible. But every script would have to carry its own local copy of luapackage.
Note: I'm looking for a Lua solution, avoiding binary packages that could compromise cross-compatibility.
You can use debug.getinfo(1,"S").source to get the location of the current (module) file. Replace luamodule.lua with data.txt, remove leading #, and you should get the path you need.

Resources