Argument 1 missing or nil

  1. What do you want to achieve?
  • I want the Rig called “Rat” to move to a random player, deal damage to the player and play the animation.
  1. What is the issue? Keep it simple and clear!
  • Argument 1 missing or nil.
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • I’ve looked everywhere but haven’t gotten any luck.

Any tips, hints or help would be very appreciated! :slightly_smiling_face:

(The script runs on the Server, Legacy RunContext, the script starts disabled, then after I load, I enable it)

local figure = script.Parent
local Debris = game:GetService("Debris")
local deb = false

wait()
function getHumanoid(model:Model)
	for i,v in ipairs(model:GetChildren()) do
		if v:IsA("Humanoid") then
			return v
		end
	end
end

function getRootPart(model:Model)
	for i,v in ipairs(model:GetChildren()) do
		if v.Name == ("HumanoidRootPart" or "RootPart" or "HumanoidRoot" or "HumanRootPart" or "HRootPart" or "HRoot" or "HrootPart" or "humanoidrootpart" or "Humanoidrootpart") then
			return v
		end
	end
end

local humanoid = getHumanoid(figure)
local rootpart = getRootPart(figure)
local Attack = humanoid:LoadAnimation(figure.Attack)
humanoid.WalkSpeed=script.Parent:GetAttribute("WalkSpeed")
Attack.Priority = Enum.AnimationPriority.Action2
Attack.Looped = false

local function getRandomPLRCharacter()
	local players = game.Players:GetPlayers()
	return players[math.random(1,#players)].Character
end

local function attack(target)
	local distance = (rootpart.Position - getRootPart(target).Position).Magnitude
	local Targethumanoid = getHumanoid(target) or target.Humanoid or target:FindFirstChildWhichIsA("Humanoid") or target:WaitForChild("Humanoid")

	if distance > 2 then -- This is the distance of studs the Smiler can hit you at.
		humanoid:MoveTo(getRootPart(target).Position)
	else
		if not target:FindFirstChild("ForceField") and not deb then
			deb = true
			Targethumanoid:TakeDamage(script.Parent:GetAttribute("Damage")) --line 43
			local s1 = figure.Head.Folder:GetChildren()
			s1[math.random(1,#s1)]:Play()
			Attack:Play()
			local ff = Instance.new("ForceField",target)
			game:GetService("Debris"):AddItem(ff,(Attack.Length + 0.2))
			deb = false
		end
	end
end

local ChosenTarget = getRandomPLRCharacter()

while true do
	task.wait(0.2)
	attack(ChosenTarget) --line 58
end

image

(The attribute “Damage” does exist)

1 Like

This error is related to calling a function and not including required parameters

try printing the attribute before the TakeDamage function if its nil then you could set it something

It prints out nil even though it’s set to 6

Make sure you set the attribute for the figure (script.Parent) on the server or before playing the game as client changes don’t replicate to a server script

First off, make sure you are doing the “:GetAttribute(“Damage”)” at the right child (it’s currently script.Parent). If that doesn’t fix it, then you might have forgotten to set the “Damage” attribute to something.

Also, suggestion! Instead of having a function “getHumanoid”, with it running though all children of ‘model’, you can just do “model:FindFirstChild(“Humanoid”)”, which will be nil if it doesn’t exist! Same goes for “getRootPart”. Just do “model:FindFirstChild(“HumanoidRootPart”)”

4 Likes

I have not realised I was attempting to get the attribute from the figure (script.Parent) model instead from the script.

Also it just feels more right to me to use a getHumanoid() function, it requires alot less typing… Eh?

Nice that you figured it out!

About the “getHumanoid” function. It’s just not necessary to loop through all children of “model”. Just using “mode:FindFirstChild(“Humanoid”)” is faster and shorter!

About the “getRootPart” function. You did 'v.Name == (“HumanoidRootPart” or “RootPart” or “HumanoidRoot” or … etc) is a bit messy, but understandable.
What it does, is checks if “HumanoidRootPart” string is NOT false/nil, which it isn’t, so THEN it’s being compared to v.Name.
If the “HumanoidRootPart” string is false/nil, then it will go to the next string, and repeat the cycle until all strings were checked.
Might have explained weirdly, but what your code does is just basically checking if ‘v.Name == “HumanoidRootPart”’, and doesn’t check the rest.

You can do the same thing as for the “getHumanoid” function. Just by doing “model:FindFirstChild(“HumanoidRootPart”)”

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.