I’m trying to make a simple command system for my mining game where I can run a command to give myself ores.
The issue is no matter what I do, when I run the command it’ll just show this error Unable to assign property Name. string expected, got nil
This is my code,
This is used in both scripts to get all ores in the game.
local OreTable = {}
for Index, Inst in ipairs(RS.StoneOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.LimestoneOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.GraniteOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.DioriteOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.SandstoneOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.ObsidianOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.CrackedLavaOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.MagmaOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.BedrockOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.LavaOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
for Index, Inst in ipairs(RS.JokeOres:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, Inst.Name:lower())
end
end
This is the serverscript
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Admins = {
2510778054,
43078752,
190238857
}
local Prefix = "/"
game.Players.PlayerAdded:Connect(function(plr)
local luck = Instance.new("IntValue", plr)
luck.Name = "luck"
luck.Value = -1
if table.find(Admins, plr.UserId) then
plr.Chatted:Connect(function(msg)
local loweredString = string.lower(msg)
local args = string.split(loweredString," ")
if args[1] == Prefix.."walkspeed" then
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
player.Character.Humanoid.WalkSpeed = args[3]
end
end
elseif args[1] == Prefix.."luck" then
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
player.luck.Value = args[3]
end
end
elseif args[1] == Prefix.."give" then
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(player.Name), 1, string.len(args[2])) == string.lower(args[2]) then
if args[4] == nil then args[4] = 1 end
if table.find(OreTable, args[3]:lower()) then
RS.Give:FireClient(player, {args[3], args[4]})
else
RS.Give:FireClient(player, {"NotFound"})
end
end
end
end
end)
end
end)
And this is the localscript.
local Inv = {}
local InventoryUI = player:WaitForChild("PlayerGui"):FindFirstChild("Inventory").Frame.ScrollingFrame
Players.PlayerAdded:Connect(function(plr)
table.clear(Inv)
for Index, Inst in ipairs(player.Inventory:GetChildren()) do
if Inst:IsA("IntValue") then
table.insert(Inv, Inst.Name)
end
end
end)
RS.Give.OnClientEvent:Connect(function(givestuff)
if givestuff[1] == "NotFound" then
game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb(255, 0, 0)\"><b>Ore not found.</b></font>")
else
if not table.find(Inv, givestuff[1]) then
local newOre = Instance.new("IntValue", player.Inventory)
newOre.Name = OreTable[tostring(givestuff[1])]
newOre.Value = givestuff[2]
local newTB = RS.TextButton:Clone()
newTB.Parent = InventoryUI
newTB.Name = OreTable[tostring(givestuff[1])]
newTB.LayoutOrder = 0
local gValue = 0
newTB.UIGradient.Color = ColorSequence.new(Color3.fromRGB(255,255,255), Color3.fromRGB(33, 33, 33))
newTB.oName.Text = table.find(OreTable, givestuff[1])
newTB.oName.TextColor3 = Color3.fromRGB(255,255,255)
newTB.oCount.Text = newOre.Value
else
local existingOre = player.Inventory:FindFirstChild(givestuff[1])
local existingUIElement = InventoryUI:FindFirstChild(givestuff[1])
local addingOn = existingOre.Value + givestuff[2]
existingOre.Value = addingOn
existingUIElement.oCount.Text = addingOn
end
end
end)
I’d appreciate any help.


