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

Why does my part disappear?

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

✓ Accepted answer

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 ;)

2 comments

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.

1

It works!

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

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