I'm working on a system that runs a RemoteEvent when a gui button is pushed.
Here we have a simplified version of my script that should provide all non functioning details.
local rem = "!armspurchase" local user = game.Players.LocalPlayer local Armors = {"GoldArmor", "SteelArmor"} for i = 1, #Armors do local Pass = user.PlayerGui.ScreenGui:findFirstChild(Armors[i].Name).TextButton Pass.MouseButton1Down:Connect(function() game:GetService("ReplicatedStorage"):FindFirstChild(rem):FireServer(user.Name, Armors[i].Name) end) end
For some reason, even though everything is accounted for, it tells me that I'm trying to index a nil value on line 8???
You created an array
holding Armour Types. I assume these Strings are relative to the Names of each Child iterated in ReplicatedStorage
. The answer to your problem is simple, you tried to use .Name
on a String inside a table. The table’s element isn’t an Object defined with this property therefore it would be a nil
property.
Simply enough it would still translate to the Armour Type without .Name
so just remove that, and you’re good to go!
Try to index the remote with a local. this can be:
local rem = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteName")
after this you just need to fire the remote.
local rem = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteName") local Armors = {"GoldArmor", "SteelArmor"} local Plr = game.Players.LocalPlayer for i,v in pairs(Armors) do v.MouseButton1Click:Connect(function() rem:FireServer(Plr[v]) end) end
Test that out