I’m working on an unlock animation for my game involving Tools and I’m trying to extract data from them such as the tool tip and item name and assigning them to Text and ImageLabels, but when I try to do so I am given errors stating that I’m attempting to either index nil or a string. The tool I’m attempting to index to is a modified variant of the Bloxy Cola, although the base of the script stays the same.
This is the code I’m using, I’ve tried researching this but to no avail, does anyone know how I would do this? I’m using an event due to the fact that the item system operates on the server
Hello, you could try using a dictionary to write defined properties to another instance. Here’s an example in code:
local fromInstance = Tool -- instance to write from
-- format: [Tool Property Name] = {[Target Instance], [Target Property Name to Write to]}
local toWrite = {
TextureId = {colaIcon,"Image"},
Name = {colaTitle,"Text"},
ToolTip = {colaTip,"Text"}
}
function writeProperties()
for fromProperty, targetInfo in pairs(toWrite) do
local targetInstance,targetProperty = unpack(targetInfo) -- splits {a,b} to a,b (tuple)
-- pcall in case any properties do not exist
local s,e = pcall(function()
targetInstance[targetProperty] = fromInstance[fromProperty]
end)
if not s then print("Error writing property",fromProperty,"of",fromInstance.Name,"to property",targetProperty,"of",targetInstance.Name..":",e) end
end
end
writeProperties()
Hope this helps!
Edited note:
If you want to implement this for multiple tools, you can just use the same instances to write to (maybe rename to more general names), and change fromInstance to your desired tool (possibly passing it as an argument of the function).
Hello, the problem is that your tools are probably in serverstorage and the client does not have access to the server storage.
A solution would be to send the information directly. :FireClient(player, Tool.TextureId, Tool.Name, Tool.ToolTip)