Then you probably didn’t do it correctly. The error clearly says you didn’t set up the BeforeRun hook. How did you set it up? Can you provide the code you used?
is it possible to make the CMDR usable only to specific people?
I’m having a very weird issue with Cmdr. I am making a viewstats command so that my Moderators can view other players stats by typing their username with the auto-complete menu if they’re in the server or use the @ prefix to type their full username if they’re not in the server. However, the issue is that when Cmdr gets to a point where it needs to return something inside the command, it just doesn’t. And that happens for every command for some really weird reason. After using commands a bunch more times, the very delayed command responses I should’ve gotten ages ago finally appear.
I tried using print statements and they got where they needed to. Once it gets to a return statement, it just self destructs.
Note: The game uses ProfileService and the game is called RoKarate. You can search it using the search bar and it’ll be the first game. I have confirmed that every variable gives what it’s supposed to such as the DataManager existing and the DataManager giving the current profile if they are in the server and all that.
Here is the following code I used:
return {
Name = "viewstats",
Aliases = {"stats"},
Description = "View a players stats.",
Group = "Moderator",
Args = {
{
Type = "player @ string",
Name = "player @ username",
Description = "The full username of the player."
}
}
}
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataManager = require(ServerStorage.DataManager) -- This does exist
local Format = require(ReplicatedStorage.Modules.FormatNumber.Simple) -- This does exist
local function toDHMS(seconds)
local days = math.floor(seconds / 86400)
local hours = math.floor((seconds % 86400) / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local seconds = math.floor(seconds % 60)
return ("%i:%02i:%02i:%02i"):format(days,hours,minutes,seconds)
end
return function(context, player)
if typeof(player) == "Instance" then
local profile = DataManager:GetProfile(player) -- This does work
context:Reply(player.Name.."'s stats:")
context:Reply("---------------------------------------------")
context:Reply("Belt: "..profile.Data.Belt)
context:Reply("Strength: "..Format.Format(profile.Data.Strength))
context:Reply("Health: "..Format.Format(profile.Data.Health))
context:Reply("MaxStamina: "..Format.Format(profile.Data.MaxStamina))
context:Reply("Wins: "..Format.Format(profile.Data.Wins))
context:Reply("Kills: "..Format.Format(profile.Data.TotalKills))
context:Reply("Robux Donated: "..Format.Format(profile.Data.RobuxDonated))
context:Reply("Playtime: "..toDHMS(profile.Data.Playtime))
context:Reply("---------------------------------------------")
return "Successfully retrieved the players stats."
elseif typeof(player) == "string" then
local gotUserId, userId = pcall(function()
return Players:GetUserIdFromNameAsync(player)
end)
if not gotUserId then
return `Failed to get UserId associated with {player}.\nError: {userId}`
end
local profileStore = DataManager:GetProfileStore()
local profile = profileStore:ViewProfileAsync("Player_"..userId)
if profile == nil then
return player.." does not have any data!"
end
context:Reply(player.."'s stats:")
context:Reply("---------------------------------------------")
context:Reply("Belt: "..profile.Data.Belt)
context:Reply("Strength: "..Format.Format(profile.Data.Strength))
context:Reply("Health: "..Format.Format(profile.Data.Health))
context:Reply("MaxStamina: "..Format.Format(profile.Data.MaxStamina))
context:Reply("Wins: "..Format.Format(profile.Data.Wins))
context:Reply("Kills: "..Format.Format(profile.Data.TotalKills))
context:Reply("Robux Donated: "..Format.Format(profile.Data.RobuxDonated))
context:Reply("Playtime: "..toDHMS(profile.Data.Playtime))
context:Reply("---------------------------------------------")
return "Successfully retrieved the players stats."
end
end