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

Why isnt my move script working?

So whenever I run the script, the fish, (Who is the one moving) juts sinks to the bottom of the tank and stays there. Any help?

fish = script.Parent

while true do
for i=1,20 do
fish.CFrame = fish.CFrame + Vector3.new(0.1,0,0)
wait(0.1)
end
for i=1,31 do
fish.CFrame = fish.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
wait(0.01)
end
for i=1,20 do
fish.CFrame = fish.CFrame - Vector3.new(0.1,0,0)
wait(0.1)
end
for i=1,31 do
fish.CFrame = fish.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.1,0)
wait(0.01)
end
end

3 comments

0

where does "i" get used?

0

Is the Fish anchored?

0

If it were anchored it wouldn't fall to the bottom.

1 answer

✓ Accepted answer

I made this base upon our script, there are a lot of improvements to make but I did not have time to finish it.

You need to store the angle and apply it to the cframe so that it faces the direction you are traveling and you need to add a method to stop if going beneath the floor.

Hope this helps you.

fish = script.Parent
function curX()
	return fish.CFrame.x
end

function curY()
	return fish.CFrame.y
end

function curZ()
	return fish.CFrame.z
end

function ran(low, high) -- hole numbers only i think?
	return math.random(low, high)
end

while true do
	for i=1,ran(1, 100) do
		fish.CFrame = CFrame.new(curX() + 0.2, curY()+ 0.1, curZ()+ ran(10,100)/100)
		wait(0.1)
	end

	for i=1,ran(10,360) do 
		fish.CFrame = CFrame.new(curX(), curY(), curZ()) * CFrame.fromEulerAnglesXYZ(0,i/100,0) 
		wait(0.01) 
	end
	
	for i=1,ran(1, 100) do
		fish.CFrame = CFrame.new(curX() - 0.2, curY() -0.1, curZ() - ran(10,100)/100)
		wait(0.1)
	end

end

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