Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script does not give player health, It kills them?

--I have edited it but it seems to still kill me.

local cyl = script.Parent

while true do
	for i = 1, 1 do
		wait(10)	
		cyl.BrickColor = BrickColor.new("Really red")
		cyl.Touched:Connect(function(Hit) 
			if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
				Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health -100
			end
			for i = 1, 1 do
				wait(10)
				cyl.BrickColor = BrickColor.new("Bright green")
				cyl.Touched:Connect(function(Hit) 
					if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
						Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health +100 
					end
				end)
			end
		end)
	end
end

--When it runs the first time it gives health, Like green give health, red kill player, then green ----kill player

--The way I intend for it to work is that there is a cylinder and if you touch it it gives you heath --and it's color is green, after a while it turns red and then it kills the player if they touch it. ---------Sorry if it's a mess

4 comments

0

When posting your question, the code you want help with can be inserted by pressing the blue Lua symbol, so that it can stay organized. The way it's written in your question is barely readable.

0

Your script is quite confusing, and I don't quite understand the use of iteration in the program. How do you intend for the script to work? Does the first touch kill, then the second heal?

0

The way I intend for it to work is that there is a cylinder and if you touch it it gives you heath and it's color is green, after a while it turns red and then it kills the player if they touch it, Sorry I just started scripting.

0

I really cant organize properly yet, I can imagine it looks like a mess to you.

1 answer

✓ Accepted answer

** You Will Need 2 Scripts for this ** You will need to put them in the same block

Script1:

--Variables--
local Brick = script.Parent
--End--

--Code--
local function PlayerTouched(Part)
	if script.Parent.BrickColor == BrickColor.new("Really red") then
		local Parent = Part.Parent
		if game.Players:GetPlayerFromCharacter(Parent) then
			Parent.Humanoid:TakeDamage(100)
		end
		if Brick.BrickColor == BrickColor.new("Bright green") then
			local Parent = Part.Parent
			if game.Players:GetPlayerFromCharacter(Parent) then
				Parent.Humanoid.Health = Parent.Humanoid.MaxHealth
			end
		end
	end
end
Brick.Touched:connect(PlayerTouched)

Script2:

while true do
	script.Parent.BrickColor = BrickColor.new("Really red")
	wait(10)
	script.Parent.BrickColor = BrickColor.new("Bright green")
	wait(10)
end

2 comments

0

Thank you so much, you are a CHAD.

0

remember, when you want to damage a humanoid use Humanoid:TakeDamage(DamageNo) instead of Humanoid.Health = Humanoid.Health - DamageNo, because if you do that, you wont damage the humanoid properly and it glitches out

This discussion is preserved as it was. New answers, comments, and votes are closed.