[Error] making a killbrick

--[[ want to make a part damage you if you are under than 50 hp, then you can regain 70 hp and
it'll damage you again.--]]
for i, v in pairs(game.Workspace:GetChildren()) do
	if v:IsA("Part", game.Workspace) then
		local function DealDamage(v)
		local hum = v.Parent:FindFirstChild("Humanoid")
		if hum then
			hum.Health = hum.Health - 1
			   while hum.Health ==- 50 do
					hum.Health = hum.Health - 0
					if hum.Health == 70 then
						hum.Health = hum.Health - 1
						return
					end
			   end
			end
		end
	end
end
local v2 = script.Parent 
v2:IsA("Part", game.Workspace)
v2.Touched:Connect(DealDamage)

I’m new to Roblox scripting but not new to Roblox studio, since I played with Roblox 2 years. Expect me to make mistakes, or as well as not explaining as clear as possible I will try to help you understand what I’m trying to do, since I’m only 11 years old. On my script, I’m trying to damage if the client or humanoid is more than 50 hp, however if it is under than 50, then the killbrick no longer damages. I’m trying to define “v2” as “v” but don’t know how to, please help me it will be my pleasure to understand and comprehend what I did wrong and as well as using different strategies since I was trying to figure it out for 4 hours. Thank you.

I can’t really tell what you were trying to do in that piece of code but this should work instead.

Edit: should probably post this in #help-and-feedback:scripting-support

local part = script.Parent

local function onTouch(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    
    if humanoid then
        if humanoid.Health > 50 then
            humanoid:TakeDamage(10) -- Amount of damage you want
        end
    end
end

part.Touched:Connect(onTouch)

1 Like

thank you soo much! Much obliged for your great response, it worked tysm!

Can you please move this post into #help-and-feedback?
And mark F311ix’s reply as solved.

how do i mark as solved im trying to already search too?

Do this, and you’ll have a option Mark as Solved on replies.

How to do that, I’ve completely forgot how to use devforum after a year

Step 1. Go to your post and click Edit (Pencil icon).
Step 2. Find a dropdown where’s Development Discussion is chosen.
Step 3. Find #help-and-feedback.

1 Like

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