Hello, I keep getting the error message “attempt to index nil with ‘Character’”. Here is my code.
Code in main script:
if args[1] == prefix.."sparkles" then
for _,v in pairs (game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(v.Name), 1, string.len(args[2])) == string.lower(args[2]) then
mod.Sparkles(player, args)
end
end
end
Code in module script:
commands.Sparkles = function(player, args)
local target = game.Players:FindFirstChild(args[2]).Character
Instance.new("Sparkles", target.HumanoidRootPart)
end
args[2] seems to be just a string referring to what the user typed for who to sparkle. The problem is since you check for partial names (if you type ae and a player is named aeq then refer to that player) you don’t change the string to the full name after finding the player. Try setting args[2] to the full player name before the mod.Sparkles call.
This:
if args[1] == prefix.."sparkles" then
for _,v in pairs (game:GetService("Players"):GetPlayers()) do
if string.sub(string.lower(v.Name), 1, string.len(args[2])) == string.lower(args[2]) then
args[2] = v.Name
mod.Sparkles(player, args)
end
end
end