You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I made a zombie that ,just like a normal zombie, follows player and attack them
it works normally when it’s a normal model but when I cloned the model (script is inside the model). the line of code that damages the player just won’t work
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried cloning the model and the whole script separately and set script.parent = clonedModel but still does’t work
The zombie follows but it doesn’t deal any damage.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
zombie script:
wait(10)
local zomHumanoid = script.Parent:FindFirstChild("Humanoid")
local zomHumanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")
local DETECTION_STUD = 100
local DAMAGE = 100
local nearestPlr = nil
local leastMag = DETECTION_STUD
local playerHit = {}
function nearestPlayer (list)
for _,plr in pairs(list) do
if (zomHumanoidRootPart.Position - plr.Character:FindFirstChild("HumanoidRootPart").Position).Magnitude <= DETECTION_STUD then
if (plr.Character:FindFirstChild("HumanoidRootPart").Position - zomHumanoidRootPart.Position).Magnitude <= leastMag then
nearestPlr = plr
leastMag = (plr.Character:FindFirstChild("HumanoidRootPart").Position - zomHumanoidRootPart.Position).Magnitude
end
end
end
zomHumanoid:MoveTo(nearestPlr.Character.PrimaryPart.Position)
end
repeat
local playerList = game:GetService("Players"):GetChildren()
nearestPlayer(playerList)
zomHumanoidRootPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Parent ~= workspace.zombieFolder and playerHit[hit.Parent] == nil then
playerHit[hit.Parent] = true
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(DAMAGE)
wait(2)
playerHit[hit.Parent] = nil
end
end)
wait(.3)
until script.Parent:FindFirstChild("Humanoid").Health == 0 or script.Parent == nil
script.Parent:Destroy()
script.Parent = nil
spawner script:
local spawner = {}
local zombie = game:GetService("ServerStorage").Zombie
local debris = game:GetService("Debris")
wait(4)
function spawner:spawnZombies(waveNum, ttl)
-- the 5 * waveNum give you 5 time the number of zombies for the waveNum
for i=1, 5*waveNum, 1 do
for _,zombiez in pairs(zombie:GetChildren()) do
local cZombie = zombiez:Clone()
cZombie.Parent = workspace.zombieFolder
debris:AddItem(cZombie, ttl)
end
-- the "i" in the z position lines them up every 10 studs
end
end
return spawner
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
thankq so much for your help