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

For and Touched not working, why?

I am trying to make a part on when touched by a humanoid, it then starts to disintegrate the limbs and then kill the player. But there is a value inside the embalming part, which when set to 0, it is off, but 1, it is on. How can I achieve this? Here are my current scripts.

Embalming script

local embalm = script.Parent
local control = script.Parent.Parent.Control
local on = control.Buttons.on
local off = control.Buttons.off
local Touched = embalm.Touched.Parent:GetChildren()
local value = script.Parent.On.Value

embalm.Touched:connect(function()
	if value == 1 then
		for i = 100,0,1 do
			Touched.Parent.Humanoid.Health = -1
			Touched.Transparency = -.1
			wait(0.1)
		end	
	elseif value == 0 then
end
end)

On/Off script

Off

local value = script.Parent.Parent.Parent.Parent.embalm.On.Value
script.Parent.MouseButton1Click:connect(function()
	if value == 1 then
	   value = 0
	elseif value == 0 then
	end
end)

On

local value = script.Parent.Parent.Parent.Parent.embalm.On.Value
script.Parent.MouseButton1Click:connect(function()
	if value == 0 then
		value = 1
	elseif value == 1 then
	end
end)

http://www.roblox.com/Umg-item?id=340197036

3 comments

0

Is |script.Parent.On.Value| a boolvalue or something else?

0

NumberValue

0

You did your for loop backwards (for i = 100,0,1 >>> for i = 0,100,1)

1 answer

✓ Accepted answer

1. You did not define the third parameter of the for loop properly

If you want to take away a value, put -1 instead of 1. So:

for i = 100,0,-1 do

2. You are not taking the values away from the health and transparency properly

To take away from something:

val = val - 1

So:

Touched.Parent.Humanoid.Health = Touched.Parent.Humanoid.Health - 1
Touched.Transparency = i

The reason I set the transparency to i is because your for loop does all of the math for you.

End Result

for i = 100,0,-1 do
	Touched.Parent.Humanoid.Health = Touched.Parent.Humanoid.Health - 1
	Touched.Transparency = i
	wait(0.1)
end

Hope I helped ;3

~TDP

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