I’m trying to make a command that punishes a player with a yellow card using a command.
Code:
Function = function(plr,args)
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local YCEvent = ReplicatedStorage:WaitForChild("PunishYC")
local notifyEvent = ReplicatedStorage:WaitForChild("NotificationEvent")
if not args[1] then return end
args[2] = args[2] or ""
local name = args[1]
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Name:sub(1,#name):lower() == name:lower() then --error here
YCEvent:FireClient(v,args[2])
notifyEvent:FireAllClients("",true,v.Name..' got a yellow card. '..workspace.Scoreboard.Timer.Minutes.Value..':'..workspace.Scoreboard.Timer.Seconds.Value,true,"yellow")
break
end
end
end
But when running the command (using HD admin to run it as a custom command) it errors as:
- attempt to get length of a Instance value
And i’m unsure what causes it exactly, i’ve tried looking for solutions on the wiki and on the devforum without any results, i’m sure it’s some small mistake i just can’t seem to find where it is.
args[1] would be the player’s username, args[2] would be the message after the player’s name so, :yc (player)(string), the fire event shows a GUI to the player who got carded and then proceeds to print it to a log, i tried using another admin system which supports custom commands (Adonis) and the command works fine ,seems to be an issue with HD admin somehow?
Could you show the args table, in your command template?
I think you may be using a player object as an argument in the args table, so the first argument is actually a Player class instead of the name, which would mean you wouldn’t need the loop.
The error would make sense then, as you are trying to get the length of an Instance.
The solution i stated does work, but it made the second argument duplicate itself (reason), changing the code to:
Function = function(plr,args)
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local YCEvent = ReplicatedStorage:WaitForChild("YCEvent")
local notifyEvent = ReplicatedStorage:WaitForChild("NotificationEvent")
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
YCEvent:FireClient(v,args[2])
notifyEvent:FireAllClients("",true,v.Name..' got a yellow card. '..workspace.Scoreboard.Timer.Minutes.Value..':'..workspace.Scoreboard.Timer.Seconds.Value,true,"yellow")
break
end
end
};