Hi,I am trying to make a "mobile support " for my inventory so basically when I click the button it will clone that Part to my character, anyways.The table is returning nil from “hotbar” variable I don´t know why buy can someone fix it? Also I dont wanna make that the table will repeat insideany loop.
Thanks for help!
Normal script:
-- local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hotbar = script.Parent.Hotbar
hotbarTable = hotbar:GetChildren()
local module = require(script.Parent.ModuleScript)
module.Loop()
print(module.hotbar)
for _,v in pairs(module.hotbar) do
if v:IsA("ImageButton") then
v.Activated:Connect(function()
ReplicatedStorage:WaitForChild("MobileSupport"):FireServer(v:FindFirstChildWhichIsA("Tool"))
end)
end
end
Module script:
local module = {}
module.Loop = function()
game:GetService("RunService").Heartbeat:Connect(function()
print("This is running")
module.hotbar = script.Parent.Hotbar:GetChildren()
end)
end
return module
And also check out this topic on how to use module scripts more efficently it really helped me to understand how to get variables from tables that are in a function scope, to use metatables.
Oh,Thanks for all I need it is just to update a table without repeating the for i,v in pairs loop do you know how to do smth like that? Should I also watch GnoCode´s video about Metatables?
now i dont exactly know why did you use for loops for this but after that event you can just insert the values you want into a table (even though there are no tables used in these scripts)
Thanks for that by you I figured it out that I can just put a local script inside that ImageButton that is cloned.And I really just dont need to use for loops.
No problem! it would be even better if you marked my idea as “solution” so other scripters with problems like these can search this topic and get help too!