I’m making a chat module, but for some reason the morph command is telling me it is unable to cast Instance to int64, which seems weird because I turned it into a number and made sure I didn’t switch arguments. I don’t know what to fix.
Code:
local commandmodule = {}
local plrService = game:GetService("Players")
commandmodule.Commands = {
":kick",
":kill",
":heal",
":damage",
":plrMorph"
}
function commandmodule.morph(morphChar, ID)
local humDesc = plrService:GetHumanoidDescriptionFromUserId(ID) --Errors here when I call it in chat
humDesc.Parent = morphChar
end
function commandmodule.messaged(msg)
local splitstring = string.split(msg, " ")
local stringp1 = splitstring[1]
for i, v in pairs(commandmodule.Commands) do
local chosenCommand = commandmodule.Commands[i]
if stringp1 == chosenCommand then
if i == 1 then
local plrName = splitstring[2]
local reason = splitstring[3]
local findPlayer = plrService:FindFirstChild(plrName)
if findPlayer then
findPlayer:Kick("You have been kicked. Reason: " .. reason)
else
print("Error: Player cannot be found")
end
elseif i == 2 then
local plrName = splitstring[2]
local target = plrService:FindFirstChild(plrName)
if target then
local targetChar = target.Character
targetChar:WaitForChild("Humanoid").Health = 0
else
print("Error: Player cannot be found")
end
elseif i == 3 then
local plrName = splitstring[2]
local heal = splitstring[3]
local findPlr = plrService:FindFirstChild(plrName)
if findPlr then
local char = findPlr.Character
char:WaitForChild("Humanoid").Health += heal
else
print("Error: Player cannot be found")
end
elseif i == 4 then
local plrName = splitstring[2]
local dmg = splitstring[3]
local lookForPlayer = plrService:FindFirstChild(plrName)
if lookForPlayer then
local char = lookForPlayer.Character
char:WaitForChild("Humanoid").Health -= dmg
else
print("Error: Player cannot be found")
end
elseif i == 5 then
local plrName = splitstring[2]
local plrID = splitstring[3]
local lookForPlayer = plrService:FindFirstChild(plrName)
if lookForPlayer then
commandmodule:morph(lookForPlayer.Character, tonumber(plrID))
lookForPlayer.CharacterAdded:Connect(commandmodule.morph(lookForPlayer.Character, tonumber(plrID)))
lookForPlayer:LoadCharacter()
else
print("Error: Player cannot be found")
end
end
end
end
end
return commandmodule
(Note: I edited the code a but but only to check the type of the player ID)
Further information: it seems like the number has been converted to an instance when the morph function has been called…
The line that you edited was the wrong one and the error was replaced by another one: Argument 1 missing or nil.
New code:
local commandmodule = {}
local plrService = game:GetService("Players")
commandmodule.Commands = {
":kick",
":kill",
":heal",
":damage",
":plrMorph"
}
function commandmodule.morph(morphChar, ID)
print(typeof(ID))
local newID = tonumber(ID)
local humDesc = plrService:GetHumanoidDescriptionFromUserId(newID) --Argument 1 missing or nil
morphChar.Humanoid:ApplyDescription(humDesc)
end
function commandmodule.messaged(msg)
local splitstring = string.split(msg, " ")
local stringp1 = splitstring[1]
for i, v in pairs(commandmodule.Commands) do
local chosenCommand = commandmodule.Commands[i]
if stringp1 == chosenCommand then
if i == 1 then
local plrName = splitstring[2]
local reason = splitstring[3]
local findPlayer = plrService:FindFirstChild(plrName)
if findPlayer then
findPlayer:Kick("You have been kicked. Reason: " .. reason)
else
print("Error: Player cannot be found")
end
elseif i == 2 then
local plrName = splitstring[2]
local target = plrService:FindFirstChild(plrName)
if target then
local targetChar = target.Character
targetChar:WaitForChild("Humanoid").Health = 0
else
print("Error: Player cannot be found")
end
elseif i == 3 then
local plrName = splitstring[2]
local heal = splitstring[3]
local findPlr = plrService:FindFirstChild(plrName)
if findPlr then
local char = findPlr.Character
char:WaitForChild("Humanoid").Health += heal
else
print("Error: Player cannot be found")
end
elseif i == 4 then
local plrName = splitstring[2]
local dmg = splitstring[3]
local lookForPlayer = plrService:FindFirstChild(plrName)
if lookForPlayer then
local char = lookForPlayer.Character
char:WaitForChild("Humanoid").Health -= dmg
else
print("Error: Player cannot be found")
end
elseif i == 5 then
local plrName = splitstring[2]
local plrID = splitstring[3]
local numConvertedID = tonumber(plrID)
print(typeof(numConvertedID))
local lookForPlayer = plrService:FindFirstChild(plrName)
if lookForPlayer then
commandmodule:morph(lookForPlayer.Character, numConvertedID)
lookForPlayer.CharacterAdded:Connect(commandmodule.morph(lookForPlayer.Character, numConvertedID))
lookForPlayer:LoadCharacter()
else
print("Error: Player cannot be found")
end
end
end
end
end
return commandmodule
It gave new error because I used tonumber in the defining part of the function morph
Excuse me if I’m wrong, as I haven’t done much with scripting in the past year. But it seems like the humanoid (morphChar.Humanoid), doesn’t exist, hence the “attempt to index nil with ‘ApplyDescription’”