Hi! I am working on my first boss battle, and I have two problems. But it would be nice if someone could even solve one of both
The main code snippet with the problems is this:
for _,Part in ipairs(Golem:GetDescendants()) do --For each part in the Golem body
if Part:IsA("BasePart") then --Filter out the baseparts from other things
local Event = Part.Touched:Connect(function(hitpart) --If some part touches something
print("Part was touched")
if hitpart.Parent:FindFirstChild("Humanoid") then --Control if the hitted Instance has a humanoid object
print("Humanoid found")
hitpart.Parent.Humanoid:TakeDamage(90) --If yes, it's a player and damage it
Humanoid.WalkSpeed = 16
print("End of the charge")
return -- <<--HERE I want to break
end
end)
table.insert(Events, #Events+1, Event)
end
end
First Problem
I my loop (watch above). Now, I know how to break basics loops, and I thought this would be the same case as all my others loops, but if I put a break keyword there, the script editor tells me this error: syntax error: break satement must be inside a loop
.But, from that what I learned, this IS a loop, a generic for loop (correct me if I am wrong). So, whatâs going wrong there?
Second Problem
Now, if I try this script (without trying to break it), at the charging, my Boss will not damage me, but I canât find out why. I will try to explain it:
- It should, for each part of the body of the boss, make an event for every time that this part is touched
- If it finds something that has a humanoid inside (our player), make the boss damage it and he walk normally (The boss is very fast while he charges, this is why I make him go slower)
It should be easy, but there are my problems: - The boss still walks fast
- The boss dosenât do damage to the player
I tried to debug it using the print function and the Lua debugger, but (again, this âbutâ):
- It dosenât print anything
- The Lua debugger dosenât let me see what happens inside the event
At result: I canât inspect my own code!
At this point I really donât know what else to do, I tried everything what I could. For my first problem I tried to search how to break a for in pairs loop, but I found nothing. For my second problem I donât even know whatâs happening, so I canât research. I am stuck here, and I canât continue without finish this part. So, even if you only know one solution, please tell it me
Thanks for reading!
~~Eterna