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

Why does my part disappear?

Asked by 10 years ago
local cleaver = script.Parent
local handle = cleaver.Parent.WheelHandle

function CleaverActivate()
    x = 8
    repeat
        cleaver.Position = Vector3.new(-26, x, -26.5)
    wait(0.000125)
    x = x-0.1
    until x == 4
    x=4
    repeat --This is the part that doesn't work
        cleaver.Position = Vector3.new(-26, x, -26.5)
        wait(0.625)
        x = x+0.1
    until x == 8.4
end

handle.Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
        CleaverActivate()
    end
end)

This is what I've done. I activate the function, the function does its thing (It makes the cleaver fall down) but the cleaver does not go back up again.

2 answers

Log in to vote
1
Answered by 10 years ago

Use while loops for this:

local cleaver = script.Parent
local handle = cleaver.Parent.WheelHandle

function CleaverActivate()
    x = 8
    while x > 4 do
        cleaver.Position = Vector3.new(-26, x, -26.5)
        wait(0.000125)
        x = x-0.1
    end
    while x < 8.4 --This is the part that doesn't work
        cleaver.Position = Vector3.new(-26, x, -26.5)
        wait(0.625)
        x = x+0.1
    end

handle.Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
        CleaverActivate()
    end
end)

When you used the repeat/until loop, in the first one, was the part still going down/up or anywhere? Or just disappeared? If so then it happens because the loop is so fast and since you used the "==" it only works when the x IS SAME AS the value given, it occurs because the variable is updating too fast and miss some points, use the while loop and the < or > conditions ;)

0
The first loop worked, the part flew downwards just like expected. I'm going to try to see if this works, it looks like it works. crabbydarth2122 20 — 10y
1
It works! crabbydarth2122 20 — 10y
Ad
Log in to vote
1
Answered by
JoLLDS 5
10 years ago

Try this: ~~~~~~~~~~~~~~~~~ local cleaver = script.Parent local handle = cleaver.Parent.WheelHandle

function CleaverActivate()
    x = 8
    while x > 4 do
        cleaver.CFrame = CFrame.new(-26, x, -26.5)
    wait(0.000125)
        x = x-0.1
    end
    while x < 8.4 --This is the part that doesn't work
        cleaver.CFrame = CFrame.new(-26, x, -26.5)
        wait(0.625)
        x = x+0.1
    end

handle.Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
        CleaverActivate()
end
end)

~~~~~~~~~~~~~~~~~

Using vector3 object will move in a empty space, using CFrame, he can cross

Answer this question