Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

For and Touched not working, why?

Asked by 8 years ago

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

0
Is |script.Parent.On.Value| a boolvalue or something else? CodeSponge 125 — 8y
0
NumberValue TheHospitalDev 1134 — 8y
0
You did your for loop backwards (for i = 100,0,1 >>> for i = 0,100,1) TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

Ad

Answer this question