There are a couple of key issues:
- Parenting a humanoid to workspace. (This is the main issue)
- Lack of a debounce
Adding a humanoid to workspace is known to create a lot of lag. Instead, leave the created humanoid parented to nil (just do Instance.new("Humanoid")).
Additionally, it is firing a LOT. Try adding a debounce to check if the humanoid is already being processed.
(or just donât do the coding like how youâve done it..)
Purely for the sake of any (likely newer) scripters who saw it and are genuinely curious, these are some of the main issues:
You should not be using getfenv. At all. Just use normal variables.
Rather than using Instance.new in order to call functions like TakeDamage and FindFirstChildOfClass, you should instead use : rather than ., in order to pass the instance automatically (Instance.new("Humanoid").TakeDamage(humanoid, 100) â humanoid:TakeDamage(100))
the humanoid variable should be local, rather than global (humanoid = ... â local humanoid = ...)
Thereâs no reason to have return false at the end of the function.
(I am aware that the post is a troll⌠at least, I hope it isâŚ)
local DamageParts = script.Parent
for i, Part in pairs(DamageParts:GetChildren()) do
if Part:IsA("Part") then
Part.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Health = Humanoid.Health - 25
end
end)
end
end
I really like it when ragebaiters call other people ragebaiters. Everyone here, even non scripters, know that you have to use getfenv() to get the script. Lol
Iâm a scripter and I donât agree with ysing getfenv(). For a killbrick, Iâd agree with @Niklantis05. Both with the code, and the ragebait post. Iâve been scripting for 2+ yrs and iâve never had to use âgetfenv()â. Even AI can spot that this is incorect. Also it thinks the code you pasted in your example code, is unsafe. in reality, use something like what @Niklantis05 did.
local damagePart = script.Parent
local damageAmount = 100
damagePart.Touched:Connect(function(hit)
local character = hit.Parent
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(damageAmount)
end
end
end)
Highly disagree btw. Non scripters wouldnât know what getfenv() is even if their life depended on it. To me this is ragebait or something. Anyways, scripters prob wouldnât use getfenv() either. I mean a lot of devs use killbricks and 80% of them or smth like that normally donât have to post a devforum post for it.
ive been scripting for almost 2 years and i didint use getfenv a SINGLE time in my life
If thatâs your âeveryone knows thisâ, idk what era you coding in