- 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.
- What is the issue? Keep it simple and clear!
- Argument 1 missing or nil.
- 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!
(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
(The attribute “Damage” does exist)