Function calling help, what can I do to circumvent this error?
Asked by
6 years ago Edited 6 years ago
Hello, I've been trying to create an inventory system where it will redraw GUI every time the descendants of the inventory folder has been changed. I created a function to do this in a LocalScript called RedrawGrids(), but when I tried to call it using a MouseEnter I receive the following error in the output:
06:02:49.260 - Players.Rheines.PlayerGui.NewInventory.MainFrame.Inventory.Padding.LocalScript:9: attempt to call global 'RedrawGrids' (a nil value)
This is my script:
01 | local PlayerService = game:GetService( "Players" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
04 | local Player = PlayerService.LocalPlayer |
05 | local Equipped = Player:WaitForChild( "Equipped" ) |
06 | local Inventory = Player:WaitForChild( "Inventory" ) |
09 | script.Parent.MouseEnter:Connect(RedrawGrids()) |
13 | print ( 'entered function' ) |
15 | for _,guis in pairs (script.Parent:GetChildren()) do |
16 | if guis:IsA( "ImageLabel" ) then |
21 | for _,gear in pairs (Inventory:GetChildren()) do |
22 | local gui = ReplicatedStorage.ItemGUI:Clone() |
23 | gui.Name = gear.Type.Value |
24 | gui.Parent = script.Parent |
However, when I made RedrawGrids into an anonymous function such as
01 | script.Parent.MouseEnter:Connect( function () |
02 | print ( 'entered function' ) |
04 | for _,guis in pairs (script.Parent:GetChildren()) do |
05 | if guis:IsA( "ImageLabel" ) then |
10 | for _,gear in pairs (Inventory:GetChildren()) do |
11 | local gui = ReplicatedStorage.ItemGUI:Clone() |
12 | gui.Name = gear.Type.Value |
13 | gui.Parent = script.Parent |
it works perfectly fine. However, I want to call RedrawGrids as a variable so that I can reuse it as often as I like. Is there something that I did wrong?